- 在屏幕旋轉(zhuǎn)的動(dòng)畫中洒放,需要保持播放器之外的界面布局
- 全屏切換到小屏片拍,小屏需要回到原先位置
- (void)enterFullscreen {
if (self.movieView.state != MovieViewStateSmall) {
return;
}
self.movieView.state = MovieViewStateAnimating;
/*
* 記錄進(jìn)入全屏前的parentView和frame
*/
self.movieView.movieViewParentView = self.movieView.superview;
self.movieView.movieViewFrame = self.movieView.frame;
/*
* movieView移到window上
*/
CGRect rectInWindow = [self.movieView convertRect:self.movieView.bounds toView:[UIApplication sharedApplication].keyWindow];
[self.movieView removeFromSuperview];
self.movieView.frame = rectInWindow;
[[UIApplication sharedApplication].keyWindow addSubview:self.movieView];
/*
* 執(zhí)行動(dòng)畫
*/
[UIView animateWithDuration:0.5 animations:^{
self.movieView.transform = CGAffineTransformMakeRotation(M_PI_2);
self.movieView.bounds = CGRectMake(0, 0, CGRectGetHeight(self.movieView.superview.bounds), CGRectGetWidth(self.movieView.superview.bounds));
self.movieView.center = CGPointMake(CGRectGetMidX(self.movieView.superview.bounds), CGRectGetMidY(self.movieView.superview.bounds));
} completion:^(BOOL finished) {
self.movieView.state = MovieViewStateFullscreen;
}];
[self refreshStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
}
- (void)exitFullscreen {
if (self.movieView.state != MovieViewStateFullscreen) {
return;
}
self.movieView.state = MovieViewStateAnimating;
CGRect frame = [self.movieView.movieViewParentView convertRect:self.movieView.movieViewFrame toView:[UIApplication sharedApplication].keyWindow];
[UIView animateWithDuration:0.5 animations:^{
self.movieView.transform = CGAffineTransformIdentity;
self.movieView.frame = frame;
} completion:^(BOOL finished) {
/*
* movieView回到小屏位置
*/
[self.movieView removeFromSuperview];
self.movieView.frame = self.movieView.movieViewFrame;
[self.movieView.movieViewParentView addSubview:self.movieView];
self.movieView.state = MovieViewStateSmall;
}];
[self refreshStatusBarOrientation:UIInterfaceOrientationPortrait];
}
- (void)refreshStatusBarOrientation:(UIInterfaceOrientation)interfaceOrientation {
[[UIApplication sharedApplication] setStatusBarOrientation:interfaceOrientation animated:YES];
}
- (BOOL)shouldAutorotate {
return NO;
}
在iOS8.1-8.3上可以通過(guò)系統(tǒng)只允許豎屏來(lái)避免全屏右半邊無(wú)法點(diǎn)擊的問(wèn)題;
具體做法: 在進(jìn)入視頻播放vc時(shí)(在viewWillAppear:
)中設(shè)置-application:supportedInterfaceOrientationsForWindow:
的返回值為UIInterfaceOrientationMaskAllButUpsideDown
. 然后在viewWillDisappear:
中設(shè)置-application:supportedInterfaceOrientationsForWindow:
返回UIInterfaceOrientationMaskAllButUpsideDown
;