Refresh Interface Orientation of UIViewController
I have a view controller with a paging scrollview displaying pages of data to the user. I'm having trouble getting the scroll view to "snap to" pages when the user rotates the device while in the middle of scolling to the next/previous page.
I notice in the native photo viewer app that rotation is essentially disabled during scrolling. I'm开发者_C百科 trying to mimic this behaviour.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (isScrolling)
return interfaceOrientation == self.interfaceOrientation;
return YES;
}
The problem is I need some way to tell the runtime that I am ready to change my orientation. Something like setNeedsLayout but for View Controllers.
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
isScrolling = NO;
//something to get the interface orientation updated
}
It's a small problem but it's driving me nuts. Any ideas?
Pure speculation but maybe try something like this?
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}
精彩评论