shouldAutorotateToInterfaceOrientation无法正常工作(shouldAutorotateToInterfaceOrientation doesn't work properly)
如果设备是iPhone,我想锁定方向为肖像,如果设备是iPad,我想允许所有方向。
我有这个代码,但它不会在纵向模式下锁定iPhone:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { return NO; } else { if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) return YES; } return NO; }问题是什么?
I want to lock orientation to Portrait if device is iPhone, and allow all orientations if the device is iPad.
I have this code, but it doesn't lock iPhone in Portrait mode:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { return NO; } else { if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) return YES; } return NO; }What is the problem?
最满意答案
if you will navigate the view then force orientation will not work but if you will present your view then it will work very well and it works for me. In my project all screens are in portrait mode only but only one screen is in landscape mode. - (IBAction)startButtonClicked:(id)sender { CTFailure_RemedyGameViewController *remedyGameController = [[CTFailure_RemedyGameViewController alloc]initWithNibName:@"CTFailure_RemedyGameViewController" bundle:nil]; [self presentModalViewController:remedyGameController animated:NO]; [remedyGameController release]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); } @end if you will navigate the view then force orientation will not work but if you will present your view then it will work very well and it works for me. In my project all screens are in portrait mode only but only one screen is in landscape mode. - (IBAction)startButtonClicked:(id)sender { CTFailure_RemedyGameViewController *remedyGameController = [[CTFailure_RemedyGameViewController alloc]initWithNibName:@"CTFailure_RemedyGameViewController" bundle:nil]; [self presentModalViewController:remedyGameController animated:NO]; [remedyGameController release]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); } @end更多推荐
发布评论