How to prevent UIScrollView to scroll through two pages? - iphone

I have UIScrollView and i'm using it in pagingEnabled mode. In this UIScrollView,i've many images to load.So it's impossible to load all of them. I decided to load five by five. Initially, i load five images and set their position,size and tags. So far, i'm able to do this.
Once user arrives fourth page, i need to set sixth page and remove first page from superview. For that, I'm using this method to do that.
[[self.scrollView viewWithTag:currentPage-3] removeFromSuperView];
To detect page changed event properly, i've used almost all of the delegate methods of UIScrollView, but when users scrolls continuously, i've missed pages. So, i cannot load images properly. For example,when i missed to load page 6, i cannot load page 8.
I tried to disable userInteraction mode, even if it's set to NO,user can continue scrolling.
What i want to do is,when user did page changed, i want to disable UIScrollView to scroll until i finished loading images into UIScrollView.
Do you guys have any idea,how can i accomplish that ?
Thank you.

What i want to do is,when user did page changed, i want to disable UIScrollView to scroll until i finished loading images into UIScrollView.
If you want to disable scrolling after each page scroll, look to the UIScrollViewDelegate methods, like scrollViewDidScroll:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScrollViewDelegate_Protocol/Reference/UIScrollViewDelegate.html#//apple_ref/occ/intf/UIScrollViewDelegate
Within scrollViewDidScroll: you can set scrollEnabled on the UIScrollView to NO. Once you're images finish loading, re-enable scrolling through the same property.

Related

Rotating UILabels depending on page in UIScrollView like in Google+ App

I have an application with several (8) different Views in a UIScrollView. They are circling so that you get to the first when you try to get "behind" the last and vice versa.
My problem is how to create a titlebar like in the Stream of the Google+ App. There the titles are circling with the pages and show the current visible page.
How could I realize that? Would it be possible to create a general class to use such a view in many different apps?
I've already tried to solve this problem with some different approaches, but they all didn't work (well). I can display labels above my scrollView and move them, but how far and with which text seems to be difficult for me.
So now I'm looking forward to your answers ;D
Try using two UIScrollView, one for the content and one for the headers. The header UIScrollView would be controlled by your view controller that is also a delegate of the main UIScrollView. Update the header UIScrollView whenever you receive a -scrollViewDidScroll: message from the main UIScrollView.
I think you need to add label in customview and then add customviews in scrollView, you will get events for individual view, so you can rotate that view according to angle and keep label at fix place...

How does the UIScrollView delegate know about my UIScrollView ivar?

I'm working on a app that has a paging UIScrollView that contains three scrollViews as subviews which display images that you can pinch and zoom on. The code came from Apple's "PhotoScroller" sample code but I've stripped out the tiling functionality because I'm trying to master the basics first.
I can zoom in on my different images and page through them, which is great. When I leave an image that has been zoomed in to go to the next "page" of the pagingScrollView I want it to be restored to it's original zoom size, right now it stays at the zoom level that I left it at.
I imagine I need to write some code that tells the zoomed UIScrollView to go back to the appropriate zoom scale when I get to the next page. My question is how do I do that?
So far I've been working with UIScrollView's Delegate method "scrollViewDidScroll" and and the "contentOffset" property. Another thought is somehow getting a notification that the pagingScrollView has moved to the next "page."
Any ideas?
If you're interested in knowing when the scroll view has stopped (e.g. the user has let go and the scroll view has snapped into position on a new page) you can use scrollViewDidEndDecelerating:. However, the user may scroll several pages before allowing the scroller to fully stop, so the last page the user stopped on may not be the immediately preceding or immediately following page. You can keep a pointer to the current page and each time the user stops on a page restore the previously current page to the default zoom level before updating the current page pointer.

Displaying one graph per day, home screen style

I'm working on an app that can display a graph with some data, one every day. I'll call this "dayGraph".
I'd like to build an interface similar to the iPhone home screen, aka pageControl, with one dayGraph per page. (but i don't need the small dots!)
I tried with the standard pageControl example from Apple, and it's working, but only with a small number of pages. I need to display even 100 possible dayGraph, if the user wants, but the pageControl is going crazy when the page number exceed 50.
I know that the photo app is doing a similar thing, and it can work with many photos.
My question is: How can i do that? Is there any "Apple way" of doing it, or i should begin to make my own method for swapping the dayGraphs?
Thank you very much!
If your goal is to enable swipe-based paging, the view you want to use is a UIScrollView. Set its pagingEnabled property to YES. Then add each graph as a subview of your UIScrollView, setting the frame of each graph to position each one on its own page extending beyond the bounds of your UIScrollView to the right. Finally, update the contentSize property of your UIScrollView to encompass all of your pages.
Now the user can swipe left and right to flip between the pages of your scroll view.
Note: If you add 50+ subviews to your scrollview, it's likely that you'll run into memory problems. To avoid this, you'll probably want just keep subviews loaded for the current page, plus the adjacent pages to the right and left. Set a delegate on your UIScrollView to an object that implements scrollViewDidEndDecelerating:. In that method, remove any subviews that aren't on the current or adjacent pages, and make sure each adjacent page has its subview loaded. That way you'll never have more than 3 pages of content in memory at one time.

Mini Scrollbar with thumbnails on iphone

I was wondering, what would be the best way, to implement an 'extra' scrollbar, showing thumbnail versions of the pages, you are currently viewing.
In my case, I would like to have maybe around 20 images, which I would animate with Cover Flow Layers and while I 'scroll' up an down to view them, a scrollbar appears at the side, showing the smaller thumbnail versions of all the pages while the thumbnail currently visible is rendered slightly highlighted.
Is there anything specific I need to keep in mind? Thanks in advance for any ideas!
You are not giving much info to work with:)
Build a UIScrollView and a UIView, stick all the thumbnails into the UIView, stick the UIView into the UIScrollView.
If you have a lot of images, consider loading them in as "dummies/blank image" and have an NSOperation load them in the background. Consider releasing images that are outside of the screen, so that if 3-7 is on the screen then you only load in 2-8 and release everything else.
Regarding the logistics of it:
Build a viewController for holding everything. Then build a thumbnail viewController "component" that has a delegate method for setting the "displayed" image and maybe one for scroll and click.
Build a FullSize viewController component for handling the full size images. Have that also implement some delegate methods to communicate to the top most viewController. Add the two components to the top viewController, hook up the logic and you are done.
Make sure there exists only one model array/dictionary in the top most viewController and "feed" that downwards to the thumbnail and fullsize viewController, when some one clicks or scrolls, inform the top most viewController and have that update the other viewController.
Was that the kind of answers you were looking for?
:)

Strategy to lazy load images for buttons within UIScrollView?

I have a horizontal UIScrollView that contains UIButtons (though it could be any object). I would like to only download images for these buttons as the user scrolls and they are seen. I would also like an activityindicator running on each button while the images are downloading. Here's what I've tried with results:
Check content offset of uiscrollview and download images for visible buttons. Problem: issues getting activity view shown within subclassed UIButton and not desired usability since images are only downloaded once scrolling stops.
Add subviews (not buttons) to the UIScrollview hoping to use the view's ViewController to initiate a downloaded on viewDidAppear. Problem: viewDidAppear never seems to get called (because I am using addSubView?).
I've seen other apps that do this kind of loading but need some guidance on the typical set-up. Ebay's app is a great example. All items have a default image until the item comes into view, then an activityindicator runs and the items unique image is downloaded.
Thanks for assistance.
Without actually trying it out, here's my idea:
You can use the UIScrollViewDelegate method scrollViewDidScroll: to find out when your scroll view finished scrolling and then use [UIScrollView contentOffset] to determine which part of the scroll view is visible and (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view to determine the button's position within the visible part of the scroll view. Have a method that checks if the button has had its image loaded yet and if not, load it and refresh the view if necessary.
Most such apps are using a UITableView, not a plain scroll view. Joe Hewitt's Three20 framework has a TTImageView class that can do lazy image loading and is pretty well suited to this kind of use.