我正在为iPad制作相机应用程序。我希望相机应用程序仅在纵向模式下工作。我必须进行旋转观察,并强制设备使用纵向模式,如下所示:
UIImagePickerController in Landscape
我认为这是私有API;该帖子中的一些用户表示它是。
如果是这样,我可以使用哪些其他工作来强制叠加层仅保持纵向模式?如果我不添加此代码,它将旋转为纵向和横向模式。
//Is this private?
@interface UIDevice ()
-(void)setOrientation:(UIDeviceOrientation)orientation;
@end
-(IBAction)InitiateCamera
{
overlayview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
...
...
//monitor device rotation
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
//launch camera
[self presentViewController:picpicker animated:YES completion:nil];
}
- (void) didRotate:(NSNotification *)notification
{
//IS THIS PRIVATE?
//Maintain the camera in portrait orientation
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
答案 0 :(得分:8)
请改用此代码。我提交了一个应用程序并在itunes上获得批准
- (void) didRotate:(NSNotification *)notification
{
[[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(__bridge id)((void*)UIInterfaceOrientationPortrait)];
}
答案 1 :(得分:1)
是的。虽然orientation
标题中显示UIDevice
属性,但该标题中的标记为 readonly 。