iphone应用程序在ipad上运行的问题
Posted
技术标签:
【中文标题】iphone应用程序在ipad上运行的问题【英文标题】:issues with the iphone app runs on ipad 【发布时间】:2011-09-13 04:50:39 【问题描述】:我的 iPhone 应用程序在 iPad 上运行时出现问题。我在第一个屏幕中使用相机覆盖视图(在应用程序启动时启动),但是当我导航到其他屏幕时,它上面有一个空白区域。这会出现仅在 iPad 上,在 iPhone 上都很好用。
这是显示空白屏幕的附加图像
相机覆盖视图代码
controlView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
controlViewLandscape = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 480, 320)];
controlView1= [[UIView alloc]initWithFrame:CGRectMake(0,170, 420, 480)];
controlViewLandscape1= [[UIView alloc]initWithFrame:CGRectMake(0, 0, 480, 320)];
anImagePickerController = [UIImagePickerController new];
anImagePickerController.view.frame=CGRectMake(0, 0, 320, 480);
anImagePickerController.delegate = self;
anImagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
anImagePickerController.cameraDevice=UIImagePickerControllerCameraDeviceFront;
anImagePickerController.showsCameraControls=NO;
anImagePickerController.wantsFullScreenLayout=YES;
anImagePickerController.cameraViewTransform=CGAffineTransformScale(anImagePickerController.cameraViewTransform, 1.16676, 1.34299);
UIButton *startbutton = [UIButton buttonWithType:UIButtonTypeCustom];
[startbutton setImage:[UIImage imageNamed:@"play2.png"] forState:UIControlStateNormal];
startbutton.frame=CGRectMake(130, 390, 55, 55);
[startbutton setTitle:@"Start" forState:UIControlStateNormal];
[startbutton addTarget:self action:@selector(startChat) forControlEvents:UIControlEventTouchUpInside];
anImagePickerController.cameraOverlayView = startbutton;
UIButton *startbutton1 = [UIButton buttonWithType:UIButtonTypeCustom];
startbutton1.frame=CGRectMake(-50, 10, 150, 30);
[startbutton1 setTitle:@"Status:" forState:UIControlStateNormal];
startbutton1.titleLabel.font=[UIFont boldSystemFontOfSize:12];
UIButton *startbutton2 = [UIButton buttonWithType:UIButtonTypeCustom];
startbutton2.frame=CGRectMake(13, 10, 150, 30);
[startbutton2 setTitle:@"Disconnected" forState:UIControlStateNormal];
startbutton2.titleLabel.font=[UIFont boldSystemFontOfSize:12];
//setting button
UIButton *settingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
settingBtn.frame=CGRectMake(272, 10, 43, 43);
//[settingBtn setTitle:@"Setting" forState:UIControlStateNormal];
[settingBtn setImage:[UIImage imageNamed:@"settings.png"] forState:UIControlStateNormal];
[settingBtn addTarget:self action:@selector(settingNavigate) forControlEvents:UIControlEventTouchUpInside];
[controlView addSubview:settingBtn];
[controlView addSubview:startbutton2];
[controlView addSubview:startbutton];
[controlView addSubview:startbutton1];
controlView.tag=10;
//for landscape
UIButton *startbuttonl = [UIButton buttonWithType:UIButtonTypeCustom];
[startbuttonl setImage:[UIImage imageNamed:@"play2.png"] forState:UIControlStateNormal];
startbuttonl.frame=CGRectMake(210, 245, 55, 55);
[startbuttonl setTitle:@"Start" forState:UIControlStateNormal];
[startbuttonl addTarget:self action:@selector(startChat) forControlEvents:UIControlEventTouchUpInside];
UIButton *startbutton1l = [UIButton buttonWithType:UIButtonTypeCustom];
startbutton1l.frame=CGRectMake(-60,-8, 150, 30);
[startbutton1l setTitle:@"Status:" forState:UIControlStateNormal];
startbutton1l.titleLabel.font=[UIFont boldSystemFontOfSize:12];
UIButton *startbutton2l = [UIButton buttonWithType:UIButtonTypeCustom];
startbutton2l.frame=CGRectMake(3, -8, 150, 30);
[startbutton2l setTitle:@"Disconnected" forState:UIControlStateNormal];
startbutton2l.titleLabel.font=[UIFont boldSystemFontOfSize:12];
//setting button
UIButton *settingBtnl = [UIButton buttonWithType:UIButtonTypeCustom];
settingBtnl.frame=CGRectMake(420,0, 43, 43);
//[settingBtn setTitle:@"Setting" forState:UIControlStateNormal];
[settingBtnl setImage:[UIImage imageNamed:@"settings.png"] forState:UIControlStateNormal];
[settingBtnl addTarget:self action:@selector(settingNavigate) forControlEvents:UIControlEventTouchUpInside];
[controlViewLandscape addSubview:settingBtnl];
[controlViewLandscape addSubview:startbutton2l];
[controlViewLandscape addSubview:startbuttonl];
[controlViewLandscape addSubview:startbutton1l];
//for landscape left
UIButton *startbuttonlr = [UIButton buttonWithType:UIButtonTypeCustom];
[startbuttonlr setImage:[UIImage imageNamed:@"play2.png"] forState:UIControlStateNormal];
startbuttonlr.frame=CGRectMake(220, 263, 55, 55);
[startbuttonlr setTitle:@"Start" forState:UIControlStateNormal];
[startbuttonlr addTarget:self action:@selector(startChat) forControlEvents:UIControlEventTouchUpInside];
UIButton *startbutton1lr = [UIButton buttonWithType:UIButtonTypeCustom];
startbutton1lr.frame=CGRectMake(-40, 20, 150, 30);
[startbutton1lr setTitle:@"Status:" forState:UIControlStateNormal];
startbutton1lr.titleLabel.font=[UIFont boldSystemFontOfSize:12];
UIButton *startbutton2lr = [UIButton buttonWithType:UIButtonTypeCustom];
startbutton2lr.frame=CGRectMake(23, 20, 150, 30);
[startbutton2lr setTitle:@"Disconnected" forState:UIControlStateNormal];
startbutton2lr.titleLabel.font=[UIFont boldSystemFontOfSize:12];
//setting button
UIButton *settingBtnlr = [UIButton buttonWithType:UIButtonTypeCustom];
settingBtnlr.frame=CGRectMake(440, 20, 43, 43);
//[settingBtn setTitle:@"Setting" forState:UIControlStateNormal];
[settingBtnlr setImage:[UIImage imageNamed:@"settings.png"] forState:UIControlStateNormal];
[settingBtnlr addTarget:self action:@selector(settingNavigate) forControlEvents:UIControlEventTouchUpInside];
[controlViewLandscape1 addSubview:settingBtnlr];
[controlViewLandscape1 addSubview:startbutton2lr];
[controlViewLandscape1 addSubview:startbuttonlr];
[controlViewLandscape1 addSubview:startbutton1lr];
//for portrait down
UIButton *startbuttonlp = [UIButton buttonWithType:UIButtonTypeCustom];
[startbuttonlp setImage:[UIImage imageNamed:@"play2.png"] forState:UIControlStateNormal];
//startbuttonlp.frame=CGRectMake(-50, 210, 55, 55);
startbuttonlp.frame=CGRectMake(50, 385, 55, 55);
[startbuttonlp setTitle:@"Start" forState:UIControlStateNormal];
[startbuttonlp addTarget:self action:@selector(startChat) forControlEvents:UIControlEventTouchUpInside];
UIButton *startbutton1lp = [UIButton buttonWithType:UIButtonTypeCustom];
startbutton1lp.frame=CGRectMake(-130, 0, 150, 30);
[startbutton1lp setTitle:@"Status:" forState:UIControlStateNormal];
startbutton1lp.titleLabel.font=[UIFont boldSystemFontOfSize:12];
UIButton *startbutton2lp = [UIButton buttonWithType:UIButtonTypeCustom];
startbutton2lp.frame=CGRectMake(-66, 0, 150, 30);
[startbutton2lp setTitle:@"Disconnected" forState:UIControlStateNormal];
startbutton2lp.titleLabel.font=[UIFont boldSystemFontOfSize:12];
//setting button
UIButton *settingBtnlp = [UIButton buttonWithType:UIButtonTypeCustom];
settingBtnlp.frame=CGRectMake(192,0, 43, 43);
// settingBtnlp.frame=CGRectMake(92, 70, 43, 43);
[settingBtnlp setImage:[UIImage imageNamed:@"settings.png"] forState:UIControlStateNormal];
[settingBtnlp addTarget:self action:@selector(settingNavigate) forControlEvents:UIControlEventTouchUpInside];
[controlView1 addSubview:settingBtnlp];
[controlView1 addSubview:startbutton2lp];
[controlView1 addSubview:startbuttonlp];
[controlView1 addSubview:startbutton1lp];
//to rotate it to landscape
CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90) );
landscapeTransform = CGAffineTransformTranslate( landscapeTransform, +90.0, +90.0 );
[controlViewLandscape setTransform:landscapeTransform];
//to rotate it to landscape right
CGAffineTransform landscapeTransformr = CGAffineTransformMakeRotation(degreesToRadian(-90) );
landscapeTransformr = CGAffineTransformTranslate( landscapeTransformr, -90, -90);
[controlViewLandscape1 setTransform:landscapeTransformr];
//to rotate it to portrait right
CGAffineTransform landscapeTransformrp = CGAffineTransformMakeRotation(degreesToRadian(180) );
landscapeTransformrp = CGAffineTransformTranslate( landscapeTransformrp, +180.0, +180.0 );
[controlView1 setTransform:landscapeTransformrp];
controlViewLandscape.tag=20;
controlViewLandscape1.tag=40;
controlView1.tag=30;
//controlView1.hidden=YES;
// controlViewLandscape.hidden=YES; // controlViewLandscape1.hidden=YES; // controlView.hidden=YES;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
if ( ([self interfaceOrientation] == UIInterfaceOrientationPortrait))
controlView.hidden = NO;
controlViewLandscape.hidden = YES;
controlView1.hidden = YES;
controlViewLandscape1.hidden = YES;
if ( ([self interfaceOrientation] == UIInterfaceOrientationLandscapeLeft))
controlView.hidden = YES;
controlViewLandscape.hidden = YES ;
controlView1.hidden = YES;
controlViewLandscape1.hidden = NO;
if ( ([self interfaceOrientation] == UIInterfaceOrientationPortraitUpsideDown ))
controlView.hidden = YES;
controlViewLandscape.hidden = YES;
controlView1.hidden = NO;
controlViewLandscape1.hidden =YES;
if ( ([self interfaceOrientation] == UIInterfaceOrientationLandscapeRight))
controlView.hidden = YES;
controlViewLandscape.hidden = NO;
controlView1.hidden = YES;
controlViewLandscape1.hidden = YES;
overlayView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 500, 500)];
[overlayView addSubview:controlView];
[overlayView addSubview:controlViewLandscape];
[overlayView addSubview:controlViewLandscape1];
[overlayView addSubview:controlView1];
//anImagePickerController.cameraOverlayView = controlView;
anImagePickerController.cameraOverlayView = overlayView;
[self.navigationController presentModalViewController:anImagePickerController animated:NO];
[anImagePickerController release];
【问题讨论】:
【参考方案1】:这可能是因为状态栏显示在 iPad 的顶部,而它存在于 iPhone 的那个白色位置。
【讨论】:
如果我删除第一个屏幕中使用的相机覆盖视图,并使用简单的视图,那么它在 iphone 和 ipad 上都可以正常工作 如何从相机叠加视图添加第一个屏幕?发布代码 我添加了用于向相机添加叠加视图的代码【参考方案2】:解决了,
使用下面一行显示状态栏
[[UIApplication sharedApplication]setStatusBarHidden:NO];
它会显示一个黑条而不是一个空白。
感谢大家的合作
【讨论】:
以上是关于iphone应用程序在ipad上运行的问题的主要内容,如果未能解决你的问题,请参考以下文章
iOS 应用程序可在 iPhone 上运行,但不能在 iPad 上运行