objective-c – UIImagePickerController(使用相机作为源代码)在
我正在尝试使用一些相机功能编写应用程序,并使用叠加视图来装饰图像.
这是我实现应用程序的方式: 这种方法很好,直到iPad2到位……它会像这样自动旋转并破坏布局: UIImagePickerController永远不会在iphone,ipod touch或原始iPad上旋转,但它在iPad2上运行. 提前致谢. 解决方法
您可以通过掠夺UIImagePickerController的叠加视图来补偿ipad的旋转. Fisrt你必须使用以下方法捕获通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationCallback:) name:nil object:nil]; 然后使用此代码: - (void) notificationCallback:(NSNotification *) notification { if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { if ([[notification name] isEqualToString:@"UIDeviceOrientationDidChangeNotification"]) { UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; switch ( orientation ) { case UIInterfaceOrientationLandscapeRight: NSLog(@"LandcapeRight"); [UIView beginAnimations:@"LandscapeRight" context:UIGraphicsGetCurrentContext()]; [UIView setAnimationDuration:0.4]; m_uiCameraOverlayView.transform = CGAffineTransformIdentity; [UIView commitAnimations]; break; case UIInterfaceOrientationLandscapeLeft: NSLog(@"LandscapeLeft"); [UIView beginAnimations:@"LandcapeLeft" context:UIGraphicsGetCurrentContext()]; [UIView setAnimationDuration:0.4]; m_uiCameraOverlayView.transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(M_PI),0); [UIView commitAnimations]; break; case UIInterfaceOrientationPortraitUpsideDown: NSLog(@"UpsideDown"); [UIView beginAnimations:@"UpsideDown" context:UIGraphicsGetCurrentContext()]; [UIView setAnimationDuration:0.4]; m_uiCameraOverlayView.transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(-M_PI / 2),-128,-128); [UIView commitAnimations]; break; case UIInterfaceOrientationPortrait: NSLog(@"Portrait"); [UIView beginAnimations:@"Portrait" context:UIGraphicsGetCurrentContext()]; [UIView setAnimationDuration:0.4]; m_uiCameraOverlayView.transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(M_PI / 2),128,128); [UIView commitAnimations]; break; default: NSLog(@"????"); break; } } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |