如果方向关闭,我使用以下代码旋转上传的jpeg图像.我只是对从iPhone和Android上传的图片有问题.
if(move_uploaded_file($_FILES['photo']['tmp_name'], $upload_path . $newfilename)){
chmod($upload_path . $newfilename, 0755);
$exif = exif_read_data($upload_path . $newfilename);
$ort = $exif['IFD0']['Orientation'];
switch($ort)
{
case 3: // 180 rotate left
$image->imagerotate($upload_path . $newfilename, 180, -1);
break;
case 6: // 90 rotate right
$image->imagerotate($upload_path . $newfilename, -90, -1);
break;
case 8: // 90 rotate left
$image->imagerotate($upload_path . $newfilename, 90, -1);
break;
}
imagejpeg($image, $upload_path . $newfilename, 100);
$success_message = 'Photo Successfully Uploaded';
}else{
$error_count++;
$error_message = 'Error: Upload Unsuccessful<br />Please Try Again';
}
Run Code Online (Sandbox Code Playgroud)
我在从jpeg读取EXIF数据的方式上做错了吗?它不是按照预期旋转图像.
当我运行var_dump($ exif)时会发生这种情况; …
是否可以设置UIImageView来处理图像方向?当我将UIImageView设置为方向为RIGHT的图像(它是来自相机胶卷的照片)时,图像会向右旋转,但我想以正确的方向显示它.
我知道我可以旋转图像数据,但它可以做得更优雅吗?
谢谢
我有一个关于如何在iOS上检测设备方向的问题.我不需要接收更改通知,只需要接收当前方向.这似乎是一个相当简单的问题,但我无法绕过它.以下是我到目前为止所做的事情:
UIDevice *myDevice = [UIDevice currentDevice] ;
[myDevice beginGeneratingDeviceOrientationNotifications];
UIDeviceOrientation deviceOrientation = myDevice.orientation;
BOOL isCurrentlyLandscapeView = UIDeviceOrientationIsLandscape(deviceOrientation);
[myDevice endGeneratingDeviceOrientationNotifications];
Run Code Online (Sandbox Code Playgroud)
在我看来这应该工作.我启用设备接收设备方向通知,然后询问它的方向,但它不起作用,我不知道为什么.
我需要检测设备何时处于纵向方向,以便我可以触发特殊动画.但我不希望我的观点自动旋转.
当设备旋转为纵向时,如何覆盖自动旋转视图?我的应用程序只需要在横向上显示它的视图,但如果我想能够检测旋转到肖像,我似乎还需要支持肖像.
我想知道如何在Swift中获得当前的设备方向?我知道有一些Objective-C的例子,但我还是无法在Swift中使用它.
我试图获取设备方向并将其放入if语句中.
这是我遇到的最多问题:
[[UIApplication sharedApplication] statusBarOrientation]
Run Code Online (Sandbox Code Playgroud) 我知道有三种方法可以获得当前的界面方向:
self.interfaceOrientation
[[UIApplication sharedApplication] statusBarOrientation]
[[UIDevice currentDevice] orientation]
他们之间有什么不同?
在给定的事件处理程序(不是"shouldAutorotateToInterfaceOrientation"方法)中,如何检测当前的iPad方向?我有一个文本字段,我必须在横向视图中设置动画(键盘出现时),但不在纵向视图中,并且想知道我在哪个方向看动画是否必要.
我正在使用MGSplitViewController,我shouldAutorotateToInterfaceOrientation
用来控制旋转时主视图控制器的大小.
它在iOS 5上运行良好,但在iOS 6(模拟器和iPad)shouldAutorotateToInterfaceOrientation
上从未调用过.
这是一个我应该期望在iOS 6的最终版本中修复的错误或者我不知道已经改变的东西吗?
我给了一个应用程序说10个视图控制器.我使用导航控制器来加载/卸载它们.
除一个以外的所有人都处于纵向模式 假设第7个VC处于景观状态.我需要它在加载时以横向呈现.
请建议在IOS 6中强制定位从纵向到横向的方法(在IOS 5中工作也很好).
以下是我在 IOS 6 之前做的事情:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
UIViewController *c = [[[UIViewController alloc]init] autorelease];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Run Code Online (Sandbox Code Playgroud)
呈现和解雇模态VC迫使应用程序检查其方向,因此shouldAutorotateToInterfaceOrientation
被调用.
我在IOS 6中尝试过的内容:
- (BOOL)shouldAutorotate{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationLandscapeLeft;
}
Run Code Online (Sandbox Code Playgroud)
在加载时,控制器保持纵向.旋转设备后,方向改变就好了.但是我需要让控制器在加载时自动旋转到横向,因此用户必须旋转设备才能正确查看数据.
另一个问题:该装置旋转回纵向后,方向变为纵向,虽然我在指定supportedInterfaceOrientations
唯一的UIInterfaceOrientationMaskLandscape
.为什么会这样?
此外,无上述3种方法越来越被调用.
一些(有用的)数据:
任何帮助表示赞赏.谢谢.
我的应用只是风景.我将这样呈现AVCaptureVideoPreviewLayer:
self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
[self.previewLayer setBackgroundColor:[[UIColor blackColor] CGColor]];
[self.previewLayer setVideoGravity:AVLayerVideoGravityResizeAspect];
NSLog(@"previewView: %@", self.previewView);
CALayer *rootLayer = [self.previewView layer];
[rootLayer setMasksToBounds:YES];
[self.previewLayer setFrame:[rootLayer bounds]];
NSLog(@"previewlayer: %f, %f, %f, %f", self.previewLayer.frame.origin.x, self.previewLayer.frame.origin.y, self.previewLayer.frame.size.width, self.previewLayer.frame.size.height);
[rootLayer addSublayer:self.previewLayer];
[session startRunning];
Run Code Online (Sandbox Code Playgroud)
self.previewView的框架为(0,0,568,320),这是正确的.self.previewLayer记录一个(0,0,568,320)的帧,这在理论上是正确的.但是,相机显示在横向屏幕中间显示为纵向矩形,并且相机预览图像的方向错误90度.我究竟做错了什么?我需要相机预览层出现在全屏幕,在横向模式下,图像应正确导向.
orientation ×10
ios ×7
objective-c ×3
ios6 ×2
swift ×2
uidevice ×2
avcapture ×1
avfoundation ×1
exif ×1
ipad ×1
iphone ×1
php ×1
uiimage ×1
uiimageview ×1