iOS實現(xiàn)視頻播放全屏和取消全屏功能
本文實例為大家分享了iOS實現(xiàn)視頻播放和取消全屏功能具體代碼,供大家參考,具體內(nèi)容如下
iOS 視頻播放全屏和取消全屏功能實現(xiàn),所需全屏的視頻所在的vc需要導航控制器控制
自定義 全屏vc VedioPlayerViewController 并定義屬性
/// 自定義的那個視頻類 ///@property (nonatomic,strong) VedioPlayer *vedioPlayer;
在VedioPlayer中定義屬性
///視頻展示的view 的父視圖 @property (nonatomic,strong) UIView *currentSuperView;
在視頻類定義方法 全屏實現(xiàn)
///取消全屏
- (void)fullScreen:(UIBarButtonItem *)btnItem{
///視頻展示的view 的父視圖
self.currentSuperView = self.superview;
///拿到window
UIWindow *window = [UIApplication sharedApplication].keyWindow;
///全屏vc初始化
VedioPlayerViewController *vc = [VedioPlayerViewController new];
///判斷是否由導航控制器控制
if ([window.rootViewController isKindOfClass:[UINavigationController class]]) {
///拿到導航控制器控制
UINavigationController *nvc = (UINavigationController *)window.rootViewController;
///把全屏視頻的vc推進去
[nvc pushViewController:vc animated:NO];
///重新設(shè)置視頻大小
[self setFrame:CGRectMake(0, 0, vc.view.frame.size.width, vc.view.frame.size.height)];
//全屏后 按鈕綁定取消全屏方法
[self.fullScreenItem setAction:@selector(cancelFullScreen:)];
///vc.conciseVedioPlayer = self;
///添加視頻到全屏vc
[vc.view addSubview:self];
///自動播放
[vc.conciseVedioPlayer startOrStop];
}
}
在視頻類定義方法 取消全屏實現(xiàn)
- (void)cancelFullScreen:(UIBarButtonItem *)btnItem{
///拿到window
UIWindow *window = [UIApplication sharedApplication].keyWindow;
///判斷是否由導航控制器控制
if ([window.rootViewController isKindOfClass:[UINavigationController class]]) {
///拿到導航控制器控制
UINavigationController *nvc = (UINavigationController *)window.rootViewController;
///推出一個vc,自然就回到原來的視圖了
[nvc popViewControllerAnimated:NO];
///把視頻添加到原本的視圖
[self.currentSuperView addSubview:self];
///重新設(shè)置視頻大小
[self setFrame:self.currentFrame];
//取消全屏后 按鈕重新綁定全屏方法
[self.fullScreenItem setAction:@selector(fullScreen:)];
///自動播放
[self startOrStop];
}
}
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
實例講解iOS中的UIPageViewController翻頁視圖控制器
UIPageViewController更像是一個視圖容器,將每頁不同的ViewController整合,這里我們將以實例講解iOS中的UIPageViewController翻頁視圖控制器:2016-06-06
iOS開發(fā)中對文件目錄的訪問及管理的基本方法小結(jié)
這篇文章主要介紹了iOS開發(fā)中對文件目錄的訪問及管理的基本方法小結(jié),代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下2015-10-10
iOS中從網(wǎng)絡獲取數(shù)據(jù)的幾種方法的比較
IOS中獲取網(wǎng)絡數(shù)據(jù)一般有三種:1、NSURLCondition(已過時) 2、NSURLSession 3、三方庫AFNetWorking。下面通過本文給大家比較這三種方法的區(qū)別對比2017-11-11
UIImage加載圖片Images.xcassets加載方法的影響
這篇文章主要介紹了UIImage加載圖片Images.xcassets加載方法的影響的相關(guān)資料,需要的朋友可以參考下2016-12-12

