我有两个视图命名它有纵向和横向,在旋转我想切换视图。但是在加载时它工作正常但旋转它不工作。请给我打电话来解决这个问题
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
self.view = self.portrait;
}
else
{
self.view = self.landscape;
}
}
答案 0 :(得分:0)
您必须实施
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
在MainViewController类中运行,以使自动旋转工作。在参考文献中查找:Reference Documentation on ViewControllers
你可以简单地说(支持所有方向):
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
答案 1 :(得分:0)
假设您在项目设置中设置了支持的方向,则可以执行以下操作:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
添加此项将为视图控制器提供实际影响willRotateToInterfaceOrientation中所做更改的权限。
另外,尝试使用此代码在视图之间切换:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationPortrait ||
toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
[UIView transitionFromView:self.view
toView:self.portrait
duration:0.7
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished){
//do something when done with animation
}];
} else {
[UIView transitionFromView:self.view
toView:self.landscape
duration:0.7
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished){
//do something when done with animation
}];
}
}