嗨,我想知道是否有办法以编程方式获得宽度.
我正在寻找足以容纳iphone 3gs,iphone 4,ipad的东西.此外,宽度应根据设备是纵向还是横向(对于ipad)而改变.
谁知道怎么做?我一直在寻找...谢谢!
在我的iPhone OS应用程序中,我希望(需要)观察设备方向的变化,以便重新排列屏幕的某些部分.我使用的方法是用来CGRect frame = [UIScreen mainScreen].applicationFrame获取屏幕大小,并从那里计算其他控件的大小和/或位置(我也尝试过self.view.frame).
所有测试都是在Portrait模式下完成的,所以我可以专注于编写主要功能,然后再对Landscape进行一些调整.这里输入问题:-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation我在继续之前添加了一些日志来检查大小,但显然宽度和高度的值是"错误的"(我说"错误",因为乍一看这些值对我来说没有意义) .
这是一些日志记录的输出:
Landscape中"w"和"h"的值似乎与我相反 - 我期待w = 480和h = 300.
我究竟做错了什么?我用来调试的代码如下.
-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
CGRect frame = [UIScreen mainScreen].applicationFrame;
CGSize size = frame.size;
NSLog(@"%@", [NSString stringWithFormat:@"Rotation: %s [w=%f, h=%f]",
UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? "Portrait" : "Landscape",
size.width, size.height]);
}
Run Code Online (Sandbox Code Playgroud) 我在iPad应用程序中遇到了横向模式的问题.
我创建了一个非常小的新项目来显示我的问题我将pList中的UIInterfaceOrientation设置为UIInterfaceOrientationLandscapeRight
在app delegate中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window makeKeyAndVisible];
MyController *myController = [[MyController alloc] init];
[self.window addSubview:myController.view];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
在MyController中
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSLog(@"Bounds Height:%f %f", self.view.bounds.size.height, self.view.bounds.size.width);
}
Run Code Online (Sandbox Code Playgroud)
我也试过在viewDidLoad中使用相同的结果
如果我在横向保持设备的同时启动应用程序NSLog输出
Bounds Height: 1004.000000 Bounds Width: 768.000000
Run Code Online (Sandbox Code Playgroud)
我需要做些什么才能获得正确的结果?我是这个iOS编程的新手,我要做的就是将UISlider锚定到屏幕的底部,但是当我得到不正确的坐标时,我不确定该怎么做.