1
Kai MOD 第二个 VC 内,viewWillAppear: 内可以使用 [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]
|
2
txx 2014-01-19 11:09:34 +08:00
在 nav 那里下断点 你会发现 进了二级之后 没有触发 shouldAutorotate
|
3
Kai MOD |
5
txx 2014-01-19 11:27:09 +08:00
|
6
bytelee 2014-01-19 11:28:52 +08:00
直接贴给你方法看看吧:
- (void)setOristation:(UIDeviceOrientation)oritation { if (oritation != [[UIDevice currentDevice] orientation] && [[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) { SEL selector = NSSelectorFromString(@"setOrientation:"); NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]]; [invocation setSelector:selector]; [invocation setTarget:[UIDevice currentDevice]]; int val = oritation; [invocation setArgument:&val atIndex:2]; [invocation invoke]; CGRect bounds = [[UIScreen mainScreen] bounds]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3]; [UIView setAnimationCurve:2]; CGRect frame = CGRectZero; if(oritation == UIDeviceOrientationLandscapeLeft) { frame = CGRectMake(bounds.size.width-20, 0, 20, bounds.size.height); } else if(oritation == UIDeviceOrientationLandscapeRight) { frame = CGRectMake(0, 0, 20, bounds.size.height); } else if(oritation == UIDeviceOrientationPortraitUpsideDown) { frame = CGRectMake(0, bounds.size.height-20, bounds.size.width, 20); } else if(oritation == UIDeviceOrientationPortrait) { frame = CGRectMake(0, 0, bounds.size.width, 20); } self.statusBarView.frame = frame; [UIView commitAnimations]; } [UIViewController attemptRotationToDeviceOrientation]; } |
9
txx 2014-01-19 11:56:05 +08:00
|
10
txx 2014-01-19 12:00:49 +08:00 1
|
11
qdvictory 2014-01-19 12:49:01 +08:00 via iPhone
|
12
dorentus 2014-01-19 13:43:53 +08:00
只 iOS 7 的话,ViewController 子类覆盖下面两个方法就 OK 了吧:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation; - (NSUInteger)supportedInterfaceOrientations; ref: https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html |
15
parkman OP |
17
PrideChung 2014-01-19 16:15:44 +08:00
- shouldAutorotate 和 - supportedInterfaceOrientations 只有设备改变方向的时候才会被调用,光覆写着两个方法是不行的。
|
18
parkman OP |
19
qdvictory 2014-01-19 17:42:37 +08:00 via iPhone
@parkman pop出来你要旋转的还是nav bar,而不是你push出来的,你得明白了vc之间的逻辑关系才好对症下药
|
20
ZircoN 2014-01-19 18:25:37 +08:00
我看到你头像进来的。
|
24
icyalala 2014-01-19 22:46:40 +08:00
在你的NavigationController里面加几句话:
- (void)viewDidLoad { [super viewDidLoad]; self.delegate = self; } - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated { UIViewController *vc = [[UIViewController alloc] init]; [self presentViewController:vc animated:NO completion:NULL]; [vc dismissViewControllerAnimated:NO completion:NULL]; } 详情见http://stackoverflow.com/questions/15519486/presenting-navigation-controller-in-landscape-mode-is-not-working-ios-6-0 主要是,你一直是在push和pop,rootViewController始终NavigationController。不旋转设备,不会引起auto rotate动作,只能用一些其他奇葩的方法了。 你要用presentViewController,改变了rootViewController,就不会有这些问题了。 |
25
ldehai 2014-01-19 23:12:48 +08:00
在CRPortaint类中加上这个来触发方向更新
- (void)viewWillAppear:(BOOL)animated { [self presentViewController:[UIViewController new] animated:NO completion:^{ [self dismissViewControllerAnimated:NO completion:nil]; }]; } |