我的应用是专为iPhone 5设计的,但现在我正在为其他设备添加兼容性。
我在Interface Builder中创建了UIView
。我想为这个视图设置一个新框架。我在运行时检查屏幕的宽度和高度,但它没有改变视图的框架。这是我的代码:
//in viewDidLoad:
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
if (screenHeight == 480 && screenWidth == 320) {
bottomView.frame = CGRectMake(0, 60, 320, 420);
}
答案 0 :(得分:1)
转到界面构建器点击视图,要调整大小,单击属性检查器而不是单击大小,然后在viewWillAppear中选择自由格式调整视图大小,您可以通过以下方式检查查看大小: -
NSLog(@“view frame ==>%@”,NSStringFromCGRect(self.view.frame));
答案 1 :(得分:0)
创建一个返回屏幕框架信息的类。
创建一个名为FullScreen的新文件,其中UIScreen为子类
#import <UIKit/UIKit.h>
@interface FullScreen : UIScreen
+ (CGRect)iOS7StyleScreenBounds;
@end
#import "FullScreen.h"
@implementation FullScreen
+ (CGRect)iOS7StyleScreenBounds {
UIScreen *screen = [UIScreen mainScreen]; CGRect screenRect;
if (![screen respondsToSelector:@selector(fixedCoordinateSpace)] && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
screenRect = CGRectMake(screen.bounds.origin.x, screen.bounds.origin.y, screen.bounds.size.height, screen.bounds.size.width);
} else {
screenRect = screen.bounds;
}
return screenRect;
}
@end
现在在视图控制器中导入此类并调用如下:
self.view.frame = [FullScreen iOS7StyleScreenBounds];
答案 2 :(得分:0)
尝试将代码放入
- (void)viewDidAppear:(BOOL)animated;
答案 3 :(得分:0)
一个可以解决的明确解决方案是,你应该从xib中删除你的UIView并以编程方式创建它。可以通过以下代码完成:
newView=[[UIView alloc]initWithFrame:CGRectMake(0, 50, 320, 430)];
[newView setBackgroundColor:[UIColor yellowColor]];
[self.view newView];