iPhone( iPad)上的高度和宽度

iPhone( iPad)上的高度和宽度,第1张

概述这只是一个测试应用程序,只有一个AppDelegate类可以创建我创建的基于Window的应用程序,将支持的方向设置为仅限于info.plist中的格局,然后添加以下代码: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 这只是一个测试应用程序,只有一个AppDelegate类可以创建我创建的基于Window的应用程序,将支持的方向设置为仅限于info.pList中的格局,然后添加以下代码:

- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    [application setStatusbarOrIEntation:UIInterfaceOrIEntationLandscapeleft];// OverrIDe point for customization after application launch.UIAlertVIEw *test = [[UIAlertVIEw alloc] initWithTitle:@"hu" message:@"hui" delegate:nil cancelbuttonTitle:@"hi" otherbuttonTitles:nil];[test show];[window makeKeyAndVisible];    NSLog(@"win %f - %f",window.bounds.size.wIDth,window.bounds.size.height);return YES;}

如果没有设置状态栏方向的第一行,即使界面的其余部分处于横向左侧,警报视图也会以纵向显示.

无论如何,日志仍然给出了:

win 768.000000 - 1024.000000

这是错误的方式(因此当我在我的真实应用程序中添加子视图时,框架不正确)

苹果似乎已经在界面旋转方面变得非常糟糕,因为我只有问题,我不记得在iPhone上发生过这种情况,所以请有人告诉我如何解决这个问题.

我会给那些能够至少解释为什么会发生这种情况并希望提供解决方案的人提供500点声誉(这几乎不是我的声誉).

解决方法 我认为 iOS Application Programming Guide的 “Launching in Landscape Mode”主要解释了您的测试应用程序发生了什么:

Applications in iOS normally launch in
portrait mode to match the orIEntation
of the Home screen. If you have an
application that runs in both portrait
and landscape mode,your application
should always launch in portrait mode
initially and then let its vIEw
controllers rotate the interface as
needed based on the device’s
orIEntation. If your application runs
in landscape mode only,however,you
must perform the following steps to
make it launch in a landscape
orIEntation initially:

In your application’s Info.pList file,
add the UIInterfaceOrIEntation key and
set its value to the landscape mode.
For landscape orIEntations,you can
set the value of this key to
UIInterfaceOrIEntationLandscapeleft or
UIInterfaceOrIEntationLandscapeRight.

Lay out your vIEws in landscape mode
and make sure that their autoresizing
options are set correctly.

OverrIDe your vIEw controller’s
shouldautorotatetoInterfaceOrIEntation:
method and return YES only for the
desired landscape orIEntation and NO
for portrait orIEntations.

important: The preceding steps assume
your application uses vIEw controllers
to manage its vIEw hIErarchy. VIEw
controllers provIDe a significant
amount of infrastructure for handling
orIEntation changes as well as other
complex vIEw-related events. If your
application is not using vIEw
controllers—as may be the case with
games and other OpenGL ES–based
applications—you are responsible for
rotating the drawing surface (or
adjusting your drawing commands) as
needed to present your content in
landscape mode.

就您的测试应用而言,关键部分是最后一部分.您没有视图控制器,因此您完全有责任根据需要设置UI.这就是您必须手动设置状态栏方向的原因.

我读了第一段,说iOS应用程序总是以纵向模式启动,然后根视图控制器旋转其视图以立即匹配设备方向,并且一旦将其添加到窗口就没有动画.这意味着UIWindow本身不会旋转,因此其尺寸将始终以纵向方向(如tadej5553所述).此外,所有UIWindow子视图的帧也将是纵向方向(因为帧始终在父视图的坐标中定义).因此,无论您如何旋转设备,根视图控制器的框架始终都是纵向方向.但是,由于视图的bounds属性是根据其自己的坐标定义的,因此该高度宽度应反映视图的当前方向.

目前尚不清楚您要使用真实应用程序完成什么,但建议的做法是为纵向布局您的视图,然后设置其自动调整属性以处理自动旋转(无论是在应用程序启动后或之后立即发生) .

总结

以上是内存溢出为你收集整理的iPhone(/ iPad)上的高度和宽度全部内容,希望文章能够帮你解决iPhone(/ iPad)上的高度和宽度所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1086017.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存