我正在使用视图动画在视图之间切换,它的工作原理,但我遇到了界面方向的问题。
我在窗口上有两个视图。
- authenticationViewCont
- mainViewCont
两者都有一个按钮,当单击按钮时,authenticationViewCont
我将其删除并显示mainViewCont
,反之亦然。
一旦我 addSubviewauthenticationViewCont.view
并将设备置于纵向模式然后将其删除,removeFromSuperview
然后我将设备方向更改为横向,然后再次 addSubview authenticationViewCont
。它首先以纵向显示动画并在动画后改变方向。
-(void)mainToAuthentication {
CGRect originalFrame = authenticationViewCont.view.frame;
CGRect modifiedFrame = originalFrame;
modifiedFrame.origin.y = originalFrame.size.height;
// made view out from screen
authenticationViewCont.view.frame = modifiedFrame;
// add sub view on top of other views
[self.window addSubview:authenticationViewCont.view];
// transiting view from bottom to center of screen
[UIView animateWithDuration:0.5
animations:^{ authenticationViewCont.view.frame = originalFrame; }
completion:^(BOOL finished){ mainViewCont.view removeFromSuperview; }];
}
-(void)authenticationToMain {
CGRect originalFrame = mainViewCont.view.frame;
CGRect modifiedFrame = originalFrame;
modifiedFrame.origin.y = -originalFrame.size.height;
// made view out from screen
mainViewCont.view.frame = modifiedFrame;
// add sub view on top of other views
[self.window addSubview:mainViewCont.view];
// transiting view from top to center of screen
[UIView animateWithDuration:0.5
animations:^{ mainViewCont.view.frame = originalFrame; }
completion:^(BOOL finished){ authenticationViewCont.view removeFromSuperview; }];
}
如何让它以当前界面方向显示,而不是它所在的旧界面方向removeFromSuperview
?