简体   繁体   English

iPhone-无法获得界面方向

[英]IPhone - Not getting Interface Orientation

I'm trying to set another position for a UIButton when I change the orientation of my IPhone and I had the idea to implement it inside BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation. 当我更改iPhone的方向时,我试图为UIButton设置另一个位置,并且我有想法在BOOL中实现它。 Is this the right way to implement or is there any error on my code? 这是实现的正确方法,还是我的代码有任何错误? It's not printing these logs. 它没有打印这些日志。

Code: 码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

if ((interfaceOrientation == UIDeviceOrientationLandscapeLeft) ||
    (interfaceOrientation == UIDeviceOrientationLandscapeRight))
{
    NSLog(@"Csantos shouldAutorotateToInterfaceOrientation: left or right");
    [adButton setFrame:CGRectMake(100, 700, 768, 90)];
}
if ((interfaceOrientation == UIDeviceOrientationPortrait) ||
    (interfaceOrientation == UIDeviceOrientationPortraitUpsideDown))
{
    NSLog(@"Csantos shouldAutorotateToInterfaceOrientation: Portrait or UpsideDown portrait");
    [adButton setFrame:CGRectMake(0, 0, 768, 90)];
}
return YES;

} }

Regards! 问候!

shouldAutorotateToInterfaceOrientation simply specifies what rotations are supported by a UIViewController - nothing more. shouldAutorotateToInterfaceOrientation只需指定UIViewController支持哪些旋转-仅此而已。

You may consider modifying willRotateToInterfaceOrientation which is called just before a rotation is about to begin - to hide background views or other objects, for example. 您可能会考虑修改willRotateToInterfaceOrientation(在旋转即将开始之前调用),例如隐藏背景视图或其他对象。

Then, override didRotateFromInterfaceOrientation which is called after a rotation has just finished - I think this one will be the most important for your setFrame: code. 然后,重写在旋转刚结束后调用的didRotateFromInterfaceOrientation-我认为这对于setFrame:代码来说是最重要的。

Your code too should work but try putting following code. 您的代码也应该可以,但是请尝试放置以下代码。 Change is from UIDeviceOrientation to UIInterfaceOrientation 更改是从UIDeviceOrientationUIInterfaceOrientation

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight))
    {
        NSLog(@"Csantos shouldAutorotateToInterfaceOrientation: left or right");
        [adButton setFrame:CGRectMake(100, 700, 768, 90)];
    }
    if ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))
    {
        NSLog(@"Csantos shouldAutorotateToInterfaceOrientation: Portrait or UpsideDown portrait");
        [adButton setFrame:CGRectMake(0, 0, 768, 90)];
    }
    return YES;
} 

I don't undestand, the adButton setFrame works correctly or not and this viewcontroller is root or you have another one. 我不理解,adButton setFrame是否可以正常工作,并且该viewcontroller是root或您还有另一个。 Can't it be that root controller shouldAutorotateToInterfaceOrientation return NO for any orientation? 根控制器是否可以在任何方向上AutorotateToInterfaceOrientation返回NO?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM