今天做了一个视频的离线缓存,视频播放我想实现自动横屏,整网都是继承MPMoviePlayerViewController重写
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIDeviceOrientationIsLandscape(interfaceOrientation);
}
然而这是iOS6就废弃的方法,使用一直警告,关键好像还不生效,搜索到另外一篇文章虽然没实现,但是还是感谢作者给我的思路(链接),下面说我的实现方式:
1.同样自己写一个类继承MPMoviePlayerViewController,在viewDidLoad中:
- (void)viewDidLoad {
[super viewDidLoad];
self.view.frame = CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.width);
self.view.center = CGPointMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2);
CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2);
[self.view setTransform:transform];
}
这样在调用的时间普通初始化调用就可以了
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
VideoListModel *model = [_dataSouce objectAtIndex:indexPath.row];
if (model.state == 2) {
NSString *path = [[MyTools pathForUrl:model.ResourceUrl] stringByAppendingString:@".mp4"];
MyMoviePlayViewController *play = [[MyMoviePlayViewController alloc] initWithContentURL:[NSURL fileURLWithPath:path]];
[self presentMoviePlayerViewControllerAnimated:play];
}
}
最后贴一张最终效果:
还算完美吧,点击完成还原竖屏;