我试图将我的 iphone 应用程序转换为 ipad,直到我的根视图控制器都很好。它是内置在代码中的,无论我做什么,我都无法调整它的大小/居中。我的主页没有笔尖。Autoresize 蒙版没有任何作用,尽管尽了最大努力,添加 iPad 笔尖也没有任何作用,但会继续在左上角显示 iphone 屏幕,并使用if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
加载一个空白的黑色 iPad 屏幕。我现在真的不知道该怎么办。如果我将我的屏幕元素设置initWithFrame:[[UIScreen mainScreen] bounds]];
为艺术品,则会因过度拉伸而变形。
// Create the main view
UIView *mainView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
mainView.backgroundColor = [UIColor blackColor];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
UIImageView *textureBg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 768.0f, 1024.0f)];
textureBg.image = [UIImage imageNamed:@"BgTexture"];
[textureBg addSubview:textureBg];
}
else {
// Add textured background
UIImageView *textureBg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320.0f, 1024.0f)];
textureBg.image = [UIImage imageNamed:@"BgTexture"];
[textureBg addSubview:textureBg];
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
UIImageView *clipBg = [[UIImageView alloc] initWithFrame:CGRectMake(7.0f, 6.0f, 605.0f, 865.0f )];
clipBg.image = [UIImage imageNamed:@"BgHomeNew2"];
clipBg.userInteractionEnabled = YES;
}
else {
// Add clipboard background
UIImageView *clipBg = [[UIImageView alloc] initWithFrame:CGRectMake(7.0f, 6.0f, 305.0f, 465.0f )];
clipBg.image = [UIImage imageNamed:@"BgHomeNew2"];
clipBg.userInteractionEnabled = YES;
//[clipBg setAutoresizingMask:(UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin )];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// Add about button to clipbg
UIButton *aboutButton = [UIButton buttonWithType:UIButtonTypeCustom];
aboutButton.frame = CGRectMake(240.0f, 90.0f, 31.0f, 33.0f);
[aboutButton setImage:[UIImage imageNamed:@"LabelButton"] forState:UIControlStateNormal];
[aboutButton addTarget:self action:@selector(aboutButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[aboutButton addSubview:aboutButton];
}
else {
// Add about button to clipbg
UIButton *aboutButton = [UIButton buttonWithType:UIButtonTypeCustom];
aboutButton.frame = CGRectMake(240.0f, 90.0f, 31.0f, 33.0f);
[aboutButton setImage:[UIImage imageNamed:@"LabelButton"] forState:UIControlStateNormal];
[aboutButton addTarget:self action:@selector(aboutButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[aboutButton addSubview:aboutButton];
}
如何为通用应用程序制作 ipad 视图,其中根视图控制器内置在代码中?我什至愿意将 iphone 屏幕简单地居中于 ipad 屏幕的中间,但由于自动调整不起作用,它只是卡在了左上角。这将是 2 分钟的 IB!
总结一下为什么下面的代码不会将图像移动到 iPad 屏幕的中心?
UIImageView *clipBg = [[UIImageView alloc] initWithFrame:CGRectMake(7.0f, 6.0f, 305.0f, 465.0f )];
clipBg.image = [UIImage imageNamed:@"BgHomeNew2"];
clipBg.userInteractionEnabled = YES;
[clipBg setAutoresizingMask:(UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin)];
编辑真的不知道我在这里错过了什么,现在已经一整天了,似乎无法在内置代码的 iphone 屏幕上追溯添加一个 xib,所以当使用 ipad 时,我会满足于在屏幕中间居中对象而不是而不是一直卡在左上角。那剂量也有效。