开发者

Refresh Interface Orientation of UIViewController

开发者 https://www.devze.com 2023-04-05 06:54 出处:网络
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 m

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];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号