我正在开发一个使用旧版 X 代码创建的 iOS 应用程序,因此它在 MainWindow.xib 中有窗口。 最近在 iOS8 Beta 版本中运行这个项目时,遇到了一个问题:窗口没有横向旋转。所以我在 MainWindow.xib 中添加了另一个窗口。我做了 if 条件来检查操作系统版本,对于旧的 iOS 版本,我使用以前创建的窗口,但对于 iOS8,我使用新添加的横向窗口。我已经解决了这个问题。除了相机,整个应用程序都正常工作。
下面是屏幕截图。
在横向模式下(正常工作):
在PortraitMode中(加载相机后,我旋转了它,这里其他控件旋转正常,但相机过度旋转不正确):
在横向模式下加载相机后,我旋转了设备,控件正确旋转但相机屏幕不旋转,它仍处于纵向模式。 这可能是由于 Appdelegate 中的窗口。
有什么解决办法吗?
提前致谢。
最佳答案
我遇到了同样的问题。
我尝试使用 cameraViewTransform。
下方
#import "MyUIImagePickerController.h"
@implementation MyUIImagePickerController
bool rotateFlg = false;
UIInterfaceOrientation startupOrientation;
-(id)init{
startupOrientation = [[UIApplication sharedApplication] statusBarOrientation];
return [super init];
}
-(NSUInteger)supportedInterfaceOrientations {
// iOS 8
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) {
float lotate[4];
if (startupOrientation == UIInterfaceOrientationLandscapeRight || startupOrientation == UIInterfaceOrientationLandscapeLeft) {
lotate[0] = 90.0f;
lotate[1] = -90.0f;
lotate[2] = 180.0f;
lotate[3] = 0.0f;
} else {
lotate[0] = 0.0f;
lotate[1] = 180.0f;
lotate[2] = 90.0f;
lotate[3] = -90.0f;
}
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if(orientation ==UIInterfaceOrientationPortrait ){
CGAffineTransform __rotation = CGAffineTransformMakeRotation(lotate[0] * M_PI / 180.0f);
self.cameraViewTransform = __rotation;
rotateFlg = true;
}
else if(orientation == UIInterfaceOrientationPortraitUpsideDown){
CGAffineTransform __rotation = CGAffineTransformMakeRotation(lotate[1] * M_PI / 180.0f);
self.cameraViewTransform = __rotation;
rotateFlg = true;
} else if(orientation == UIInterfaceOrientationLandscapeLeft){
if (rotateFlg) {
CGAffineTransform __rotation = CGAffineTransformMakeRotation(lotate[2] * M_PI / 180.0f);
self.cameraViewTransform = __rotation;
rotateFlg = false;
}
}else if(orientation == UIInterfaceOrientationLandscapeRight){
if (rotateFlg) {
CGAffineTransform __rotation = CGAffineTransformMakeRotation(lotate[3] * M_PI / 180.0f);
self.cameraViewTransform = __rotation;
rotateFlg = false;
}
}
}
return UIInterfaceOrientationMaskAll;
}
@end
这似乎有效
但是源码不美...
关于objective-c - 对于旧项目,相机在 iOS8 beta 中不能正确旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25139246/