我正在尝试在Application方法中显示一个Image(而不是在控制器中)didFinishLaunchingWithOptions(它实际上是一个启动画面)。 我的代码
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 640)];
splashView.image = [UIImage imageNamed:@"splashipad.jpg"];
} else {
//doesn't matter for now
}
实际上显示的是图像,但它不是从左上角开始的。即使模拟器处于横向模式,它也会以纵向模式显示。
即使我用640反转1024它也想解决问题。
想要始终以横向模式显示启动画面。
答案 0 :(得分:0)
尝试以下方法。宽度和宽度高度可能是错误的方式,所以只需切换它们
#define HEIGHT 1024
#define WIDTH 640
( ... )
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationPortrait) {
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, HEIGHT, WIDTH)];
} else if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) {
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
}
splashView.image = [UIImage imageNamed:@"splashipad.jpg"];
} else {
//doesn't matter for now
}
答案 1 :(得分:0)
您需要设置图像视图的autoresizingMask属性 -
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 640)];
splashView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
splashView.image = [UIImage imageNamed:@"splashipad.jpg"];
} else {
//doesn't matter for now
}
答案 2 :(得分:0)
或者,您只需在部署信息中提交图像
即可我不知道4.2以下的xcode
但如果您使用4.2,则可以执行此操作
希望这有帮助;)