开发者

IOS rotate device without rotation animation

开发者 https://www.devze.com 2023-04-06 02:32 出处:网络
What would be the correct way to achieve an effect similar to the one in the standard iPod app of the iPhone - when the device is rotated to landscape mode, the view changes to cover flow, but the typ

What would be the correct way to achieve an effect similar to the one in the standard iPod app of the iPhone - when the device is rotated to landscape mode, the view changes to cover flow, but the type of transition is fade and not the rotating screen?

This is how I am loading the modal view:

- (void) willA开发者_如何学编程nimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
        carouselView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        [self presentModalViewController:carouselView animated:YES];
    }
}

Thanks!

Andrius


I later found that it is more stable to use this solution:

In the parent view controller (in my case it is tab view controller) viewdidload method add this:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

and then add this method:

- (void) didRotate:(NSNotification *)notification {     

    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    if (UIInterfaceOrientationIsLandscape(orientation) && !self.modalViewController) {
        [self presentModalViewController:carouselView animated:YES];
        [Globals sharedGlobals].startedAtLandscape = YES;
    }

    if (UIInterfaceOrientationIsPortrait(orientation) && self.modalViewController) {
        [self dismissModalViewControllerAnimated:YES];    
        [Globals sharedGlobals].startedAtLandscape = NO;
    }
}

And finally if you want to prevent the rotation animation, modify this method like this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
        return NO;
    }
    return YES;
}
0

精彩评论

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