作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
如何获取从 UIImagepickerController
中的图库中选择的视频的方向?
UIImagePickerController * videoRecorder = [[UIImagePickerController alloc] init];
videoRecorder.delegate = self;
videoRecorder.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
videoRecorder.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
[self presentViewController:videoRecorder animated:YES completion:nil];
最佳答案
从 ALAssetsLibrary 获取您的 AVAsset 并使用以下类别:
@interface ALAssetsLibrary (VideoOrientation)
+ (UIInterfaceOrientation)orientationForTrack:(AVAsset *)asset;
@end
@implementation ALAssetsLibrary (VideoOrientation)
+ (UIInterfaceOrientation)orientationForTrack:(AVAsset *)asset
{
NSArray *videoAssets = [asset tracksWithMediaType:AVMediaTypeVideo];
if (!videoAssets.count)
{
NSLog(@"No video assets found.");
return UIInterfaceOrientationPortrait;
}
// Get the video track.
AVAssetTrack *videoTrack = [videoAssets objectAtIndex:0];
CGSize size = [videoTrack naturalSize];
CGAffineTransform preferredTransform = [videoTrack preferredTransform];
// Return interface orientation based on
// the preferred transform and size of the video.
if (size.width == preferredTransform.tx &&
size.height == preferredTransform.ty)
{
return UIInterfaceOrientationLandscapeRight;
}
else if (preferredTransform.tx == 0 &&
preferredTransform.ty == 0)
{
return UIInterfaceOrientationLandscapeLeft;
}
else if (preferredTransform.tx == 0 &&
preferredTransform.ty == size.width)
{
return UIInterfaceOrientationPortraitUpsideDown;
}
else
{
return UIInterfaceOrientationPortrait;
}
}
@end
关于ios - UIImagePicker 中所选视频的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21887970/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!