在ipad中定位时框架没有变化 [英] frame doesnt changes while orientation in ipad

查看:124
本文介绍了在ipad中定位时框架没有变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的根视图控制器的viewDidLoad中,我添加了一个方向检测观察器:

In my root view controller's viewDidLoad, i added an observer for orientation detection:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willRotateToInterfaceOrientation:duration:) name:@"UIDeviceOrientationDidChangeNotification" object:nil]; 

添加了如下方法:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                duration:(NSTimeInterval)duration {
    NSLog(@"%f,%f",self.view.frame.size.width,self.view.frame.size.height);
}

我期待肖像的结果为768,1004,而期望为1004,768景观。但我的结果是两者都是768,1004。肖像有时会是748,1024。我不知道为什么这种奇怪的行为。如果您知道解决方案,请帮助我。

I was expecting the result 768,1004 for the portrait and 1004,768 for the landscape. But my result is 768,1004 for the both. sometimes it will be 748,1024 for the portrait. I dont know why this strange behaviour. If you know the solution please help me.

编辑
这个相同的代码适用于我的另一个项目,我找不到任何区别他们之间

EDIT This same code works in my another project and i couldnt find any difference between them

推荐答案

添加以下两种方法:

- (BOOL)shouldAutorotate
{
      return TRUE;
}

- (NSUInteger)supportedInterfaceOrientations
{
     return UIInterfaceOrientationMaskAll;
}

并在此处进行所有修改:

And do all modifications here:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)  interfaceOrientation duration:(NSTimeInterval)duration
{
     NSLog(@"%f,%f",self.view.frame.size.width,self.view.frame.size.height);
}  

这篇关于在ipad中定位时框架没有变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆