Iphone 如何为子视图而不是父视图强制横向?
我有一个UINavigationController(父级)正在推送UIViewController(子级)。我理解双方都需要支持:Iphone 如何为子视图而不是父视图强制横向?,iphone,objective-c,cocoa-touch,uinavigationcontroller,rotation,Iphone,Objective C,Cocoa Touch,Uinavigationcontroller,Rotation,我有一个UINavigationController(父级)正在推送UIViewController(子级)。我理解双方都需要支持: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return YES; //(interfaceOrientation == U
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES; //(interfaceOrientation == UIInterfaceOrientationPortrait);
}
但是,我不希望父对象能够旋转到横向。我如何执行这一点
更新:
我的父母已更新为:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation != UIInterfaceOrientationLandscapeRight ||interfaceOrientation != UIInterfaceOrientationLandscapeLeft )
return NO;
else
return YES;
}
但是现在子视图不旋转。在父视图控制器中,您需要实现这一点。如果您尚未对用于父级的UINAvigationController进行子类化,只需这样做并添加此方法即可
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation != UIInterfaceOrientationLandscape)
return NO;
else
return YES;
}
在子视图控制器子类中,像您所做的那样实现该方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES; //(interfaceOrientation == UIInterfaceOrientationPortrait);
}
我稍微修改了您的代码,因为UIIntefaceOrientionLandscape不使用iOS4编译。但是,孩子停止旋转。