我正在使用视图动画切换视图,但我的界面问题却存在问题。
我在窗口有两个视图。
两个都有一个按钮,当按下authenticationViewCont
按钮时,我将其删除并显示mainViewCont
,反之亦然。
一旦我将authenticationViewCont.view
添加到子视图并将设备置于纵向模式,然后将其移至removeFromSuperview
,然后我将设备方向更改为我手中的横向,然后再次添加查看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
的旧界面方向?
答案 0 :(得分:0)
我认为这里的问题是你最初在另一个上面添加一个viewController.view然后删除旧的。
window的问题只需要一个rootViewController。因此窗口只会将旋转事件传递给第一个控制器。这意味着你的第二个viewController在调用completionsBlock之前不会获得旋转事件。
我解决这个问题的方法是将这个切换代码放在窗口上的rootViewController中。然后,无论何时进行切换,您都可以传递rootviewController的当前旋转,并让您的authenticationViewController根据您传递的方向自行设置