在应用程序执行期间拦截从纵向模式到横向模式的更改

时间:2011-03-18 09:14:09

标签: iphone objective-c

您好我不明白如果用户将手机从portarait旋转到横向或从横向到纵向,如何拦截。我知道方法很少:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

但如果我把这个方法放在AppDelegate中。

任何人都可以帮助我?

4 个答案:

答案 0 :(得分:2)

这些不是UIApplicationDelegate方法,因此您的AppDelegate将不会收到它们。

它们在UIViewController中实现,您可以在其中一个视图控制器(UIViewController的子类)中覆盖它们

答案 1 :(得分:0)

您可以在您正在使用的任何或所有视图控制器中使用它。这将拦截该特定视图控制器的更改。这些是UIViewController代表,appDelegate无法访问

答案 2 :(得分:0)

每当视图控制器旋转时,您需要将这些委托方法实现到viewcontroller中。您将得到相应代表的回复。

答案 3 :(得分:0)

Andrea你可以在viewcontroller中实现这些方法,你的视图控制器负责调用那些委托方法

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (interfaceOrientation == UIInterfaceOrientationPortrait) {}
    else {}
}