Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-25-2009, 12:13 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 96
Dvdkite is on a distinguished road
Red face Detect WHAT image is actually displaying in a ScrollView

Hi Guys,

I'm getting creazy with this problem.

I put a series of images (named 1.jpg,2.jpg.....) in a scrollview.
Then I simply need to know WHAT image is actualy on the display.....

Example: I have 10 images... I scroll images and stop at image 7....
How can I obtain that "7"???

I've tryed to use
ScrollViewDidEndDragging
and ScrollViewDidEndDecelerating mothods and in both of them I've
inserted the code: myNumber = myScrollview.tag

But All I get is always ZERO! (the number "0")
It means that all images are tagged with zero???

HAve you got a solution for this?
I will really appreciate it!

Thanks ,

David
Dvdkite is offline   Reply With Quote
Old 11-25-2009, 12:39 PM   #2 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 78
Jamvert is on a distinguished road
Default

This is what it says in the documentation:

Quote:
tag
The receiver’s tag, an integer that you can use to identify view objects in your application.

@property(nonatomic) NSInteger tag

Discussion
The default value is 0. Subclasses can set this to individual tags.
So I think you have to set the tags yourself.
Jamvert is offline   Reply With Quote
Old 11-25-2009, 12:49 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 96
Dvdkite is on a distinguished road
Default

Hi Jamvert,


Thank you.

If I tag images when I put them in the scrollview ....do you think that scrollview.tag will return the tag of the displayed image on the screen?

I'm doing so many test today without success!

David
Dvdkite is offline   Reply With Quote
Old 11-25-2009, 12:58 PM   #4 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 78
Jamvert is on a distinguished road
Default

I don't know. But I would guess not. I would assume the scroll view has 0 for its tag until you set it to otherwise as well.

This may not be the easiest or most fool proof way, but you could always just use contentOffset property to see where the scroll view is at and then compare that to your image locations to figure out which one they are viewing.
Jamvert is offline   Reply With Quote
Old 11-25-2009, 01:26 PM   #5 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 96
Dvdkite is on a distinguished road
Default

Quote:
Originally Posted by Jamvert View Post
I don't know. But I would guess not. I would assume the scroll view has 0 for its tag until you set it to otherwise as well.

This may not be the easiest or most fool proof way, but you could always just use contentOffset property to see where the scroll view is at and then compare that to your image locations to figure out which one they are viewing.
If I know the direction of the scroll (left or right) I could increase/decrease a counter to determinate what is my images?
Do you think it could be an easy way to do it?

However have you got a suggestion for alternative way to recognize what image is displayed in a scrollview?

thanks again,

David
Dvdkite is offline   Reply With Quote
Old 11-25-2009, 01:51 PM   #6 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 78
Jamvert is on a distinguished road
Default

That might be an easy way to do it if you could figure out how to tell when to increment and decrement the counter.

The only suggestion I can think of is, as I mentioned before, comparing the contentOffset property to your various images to see which is currently on the screen. It will take a little math but it could definitely get the job done.

Edit: To be a bit more clear, you could compare the contentOffset and contentSize with the frame.origin and frame.size of each image to see which is on the screen.

Last edited by Jamvert; 11-25-2009 at 01:53 PM.
Jamvert is offline   Reply With Quote
Old 11-26-2009, 04:34 AM   #7 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 96
Dvdkite is on a distinguished road
Default

Quote:
Originally Posted by Jamvert View Post
That might be an easy way to do it if you could figure out how to tell when to increment and decrement the counter.

The only suggestion I can think of is, as I mentioned before, comparing the contentOffset property to your various images to see which is currently on the screen. It will take a little math but it could definitely get the job done.

Edit: To be a bit more clear, you could compare the contentOffset and contentSize with the frame.origin and frame.size of each image to see which is on the screen.

Hi Jamvert,

thanks again for your suggestion.
Do you have any code sample about how to use contentSize and OffSet property?
I'm very new about objective-C and I'm a little confused on how use contentSize...

I was thinking also to add to the scrollview a view for every image and then in that view add the image and a button ... not so elegant but it should work... ??

:-D
Dvdkite is offline   Reply With Quote
Old 11-26-2009, 12:17 PM   #8 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 78
Jamvert is on a distinguished road
Default

To set the content size you just have to do something like this, except with whatever dimensions you need to fit your whole content, I am not sure if you can do it automatically in interface builder or not:

[myScrollView setContentSize:CGSizeMake(200,300)];



Yeah that should work, adding a view with each image and a button for it.
Jamvert is offline   Reply With Quote
Reply

Bookmarks

Tags
detect, scrollview, scrollviewdidenddragging, tag

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 329
13 members and 316 guests
akacaj, alexP, ClerurcifeDer, Duncan C, givensur, GraffitiCircus, guusleijsten, JmayLive, NetGuru, Paul Slocum, Punkjumper, Sloshmonster, yys
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,883
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:46 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0