在横向模式中报告不正确的边界 [英] Reporting incorrect bounds in landscape Mode

查看:104
本文介绍了在横向模式中报告不正确的边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iPad应用程序中遇到了横向模式的问题。



我创建了一个非常小的新项目来显示我的问题
我设置UIInterfaceOrientation在应用程式委托中

   - (BOOL)pList to UIInterfaceOrientationLandscapeRight 



<应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window makeKeyAndVisible];
MyController * myController = [[MyController alloc] init];
[self.window addSubview:myController.view];

return YES;
}

在MyController中

   - (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSLog(@Bounds Height:%f%f,self.view.bounds.size.height,self.view.bounds.size.width);
}

我也试过把它放在viewDidLoad中,结果相同



如果我在横向握住设备时启动应用程序,NSLog输出

 身高:1004.000000边界宽度:768.000000 

我需要做什么才能获得正确的结果?
我是这个iOS编程的新手,所有我想做的是锚定一个UISlider到屏幕的底部,但是当我得到不正确的坐标,我不确定如何做。

解决方案

我不认为原来的问题是回答这里,因为我遇到同样的问题。



这里的关键是,如果模拟器/设备处于横向模式,然后你启动你的程序,self.view(frame或bounds)和宽度。如果你的程序已经运行,然后你旋转它给出正确的值。这只会在设备在Landscape中启动且未旋转时才会发生。



有其他人找到了解决方案,或知道我做错了什么?请&非常感谢。



可能的解决方案



viewDidLoad方法。事实证明,视图仍然在过渡。我有更好的运气,通过调用我的函数从viewDidAppear在一切完成后调用。



希望有帮助。


I am having an issue with Landscape mode in my iPad application.

I created a very small new project to show my issue I set UIInterfaceOrientation in the pList to UIInterfaceOrientationLandscapeRight

In app delegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    [self.window makeKeyAndVisible];
    MyController *myController = [[MyController alloc] init];
    [self.window addSubview:myController.view];

    return YES;
}

In MyController

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    NSLog(@"Bounds Height:%f %f", self.view.bounds.size.height, self.view.bounds.size.width);
}

I have also tried putting this in viewDidLoad with same results

If I start the application while holding the device in landscape orientation the NSLog outputs

Bounds Height: 1004.000000 Bounds Width: 768.000000

What do I need to do to get the correct results? I am new to this iOS programming, all I am trying to do is anchor a UISlider to the bottom of the screen but when I am getting the incorrect coordinates I am unsure how to do it.

解决方案

I dont think the original question was answered here because Im experiencing the same issue.

The key here is that if the simulator / device is in Landscape mode, and Then you start your program, self.view.(frame or bounds) retrieves the Portrait height and width. If your program is already running and then you rotate it gives the correct value. This only occurs when the device is started in Landscape and is not rotated.

Has anyone else found a solution to this or knows what Im doing wrong? Please & Thank you.

Possible Solution

I had previously been calling my method from the viewDidLoad method. It turns out that the view was still transitioning. I had better luck by calling my function from viewDidAppear that is called after everything is done.

Hope that helps.

这篇关于在横向模式中报告不正确的边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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