如何阻止 mainView 旋转?
我有这段代码,设置为当手机旋转到横向时使时钟视图出现,然后当它返回到纵向时使其返回到主视图。但当它返回纵向时,纵向视图处于横向模式。我该如何解决这个问题?这是我的代码。
-(void)willAnimateRotationToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
UIInterfaceOrientation toOrientation = self.interfaceOrientation;
if(toOrientation == UIInterfaceOrientationPortrait)
{
self.view = mainView;
}
else if(toOrientation == UIInterfaceOrientationLandscapeLeft)
{
self.view = clockView;
}
else if (toOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
self.view = mainView;
}
else if(toOrientation == UIInterfaceOrientationLandscapeRight)
{
self.view = clockView;
}
}
I have this code, set to make the clockView appear when the phone is rotated to landscape, and then to make it go back to the mainView when it's returned to portrait. But when it does go back to portrait, the portrait view is in landscape mode. How do i fix this? This is my code.
-(void)willAnimateRotationToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
UIInterfaceOrientation toOrientation = self.interfaceOrientation;
if(toOrientation == UIInterfaceOrientationPortrait)
{
self.view = mainView;
}
else if(toOrientation == UIInterfaceOrientationLandscapeLeft)
{
self.view = clockView;
}
else if (toOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
self.view = mainView;
}
else if(toOrientation == UIInterfaceOrientationLandscapeRight)
{
self.view = clockView;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 mainView 和 ClockView 作为视图控制器的子视图可能会更好:
这样,两个视图都会以正确的方式自动旋转,并且您的问题应该消失。
It is probably better to have both mainView and clockView as subviews of your view controller:
This way, boths views are automatically rotated in the right way and your problem should go away.