在我的应用程序中,我使用纵向导航控制器启动 secondviewcontroller,然后在第四个viewcontroller 中完成,我应该在其中旋转 iPhone 以显示图像。现在的问题是:如果在目标中我以这种方式设置方向:
我可以使用这种方法来旋转我的图像:
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
它工作正常,但我不能锁定属于navigationcontroller 的所有视图,因为它们都旋转il 纵向和横向。
第二个选项是以这种方式设置目标:
但这种结构不检测方向:
在视图中会出现:
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
[self willRotateToInterfaceOrientation:orientation duration:1];
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
}
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
}
else
{
}
}
else{
if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
}
else
{
}
}
}
什么是最好的解决方案?谢谢