iOS小窗播放 手勢拖動

```

#import "SVP.h"

#import "LBHLivePlayerViewController.h"

#import "LBHLivePlayerView.h"

@interface LBHLivePlayerViewController (){

SVPVideo *_video;

SVPPlayerList *_playList;

CGPoint pointLeftTop;

BOOL _viderIsEnd;

}

@property (assign, nonatomic) CGPoint beginpoint;

@property (assign, nonatomic) UIPanGestureRecognizer* pan;

@end

@implementation LBHLivePlayerViewController

//

static NSString *SVPMode = nil;

- (void)viewDidLoad {

[super viewDidLoad];

self.pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];

[self.view addGestureRecognizer:self.pan];

NSNotificationCenter * orientChange = [NSNotificationCenter defaultCenter];

[orientChange addObserver:self selector:@selector(orientChangeLive:) name:UIDeviceOrientationDidChangeNotification object:nil];

// [self.video addObserver:self forKeyPath:@"isEnd" options:NSKeyValueObservingOptionNew context:nil];

}

-(void)orientChangeLive:(NSNotification*)notification{

UIDeviceOrientation? orient = [UIDevice currentDevice].orientation;

switch (orient)

{

case UIDeviceOrientationFaceUp:

[self pansmall];

break;

case UIDeviceOrientationPortrait:

[self pansmall];

break;

case UIDeviceOrientationLandscapeLeft:

[self panlang];

break;

case UIDeviceOrientationUnknown:

[self pansmall];

break;

case UIDeviceOrientationLandscapeRight:

[self panlang];

break;

default:

[self pansmall];

break;

}

}

//-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {

//

//? ? if (self.video.isEnd) {

//? ? ? ? _viderIsEnd=YES;

//? ? ? ? }else{

//? ? ? ? ? ? self.alertIsEndBtn.hidden=YES;

//? ? ? ? }

//

//? ? }

//}

-(void)panlang{

[self.view removeGestureRecognizer:self.pan];

[self.skinView addGestureRecognizer:self.pan];

}

-(void)pansmall{

[self.skinView removeGestureRecognizer:self.pan];

[self.view addGestureRecognizer:self.pan];

}

- (void)setPlayWindowStatus:(SVPlayerWindowsStatus)aWindowStatus

{

if (_playWindowStatus != aWindowStatus)

{

_playWindowStatus = aWindowStatus;

switch (_playWindowStatus) {

case SVPlayerOrientationPortraitNormal:

{

self.view.frame =CGRectMake(0, 0, Screen_Width, Screen_Height);

}

break;

case SVPlayerOrientationPortraitMini:

{

[UIView animateWithDuration:0.2 animations:^{

self.view.frame =CGRectMake(100,50,90,160);

}];

}

break;

case SVPlayerOrientationLandscapeNormal:

{

self.view.frame =CGRectMake(0, 0, Screen_Width, Screen_Height);

}

break;

case SVPlayerOrientationLandscapeMini:

{

[UIView animateWithDuration:0.2 animations:^{

self.view.frame =CGRectMake(Screen_Width-10-180,50,160,102);

}];

}

break;

default:

break;

}

}

}

- (Class)playerSkinClass{

return [LBHLivePlayerView class];

}

-(void)pan:(UIPanGestureRecognizer *)panGes{

if (_playWindowStatus == SVPlayerOrientationPortraitMini || _playWindowStatus == SVPlayerOrientationLandscapeMini)

{

UIView *piece = [panGes view];

CGPoint translation = [panGes translationInView:[piece superview]];

if ([panGes state] == UIGestureRecognizerStateBegan || [panGes state] == UIGestureRecognizerStateChanged) {

//? ? ? ? ? ? [UIView animateWithDuration:0.2 animations :^{

//

//? ? ? ? ? ? ? ? [piece setCenter:CGPointMake([piece center].x + translation.x,

//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [piece center].y + translation.y)];

//

//? ? ? ? ? ? ? ? [panGes setTranslation:CGPointZero inView:[piece superview]];

//? ? ? ? ? ? }];

[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

[piece setCenter:CGPointMake([piece center].x + translation.x,

[piece center].y + translation.y)];

[panGes setTranslation:CGPointZero inView:[piece superview]];

} completion:^(BOOL finished) {

}];

}

if([panGes state] == UIGestureRecognizerStateEnded){

if (_playWindowStatus == SVPlayerOrientationLandscapeMini )

{

[UIView animateWithDuration:0.2 animations:^{

if(([piece center].x + translation.x)<90){

[piece setCenter:CGPointMake(90,[piece center].y + translation.y)];

[panGes setTranslation:CGPointZero inView:[piece superview]];

}

if (([piece center].x + translation.x)>Screen_Width-90) {

[piece setCenter:CGPointMake(Screen_Width-90,[piece center].y + translation.y)];

[panGes setTranslation:CGPointZero inView:[piece superview]];

}

if (([piece center].y + translation.y)>Screen_Height-51) {

[piece setCenter:CGPointMake([piece center].x + translation.x,Screen_Height-51)];

[panGes setTranslation:CGPointZero inView:[piece superview]];

}

if (([piece center].y + translation.y)<51) {

[piece setCenter:CGPointMake([piece center].x + translation.x,51)];

[panGes setTranslation:CGPointZero inView:[piece superview]];

}

}];

}

if (_playWindowStatus == SVPlayerOrientationPortraitMini){

[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];

[UIView animateWithDuration:0.2 animations:^{

if(([piece center].x + translation.x)<45){

[piece setCenter:CGPointMake(45,[piece center].y + translation.y)];

[panGes setTranslation:CGPointZero inView:[piece superview]];

}

if (([piece center].x + translation.x)>Screen_Width-45) {

[piece setCenter:CGPointMake(Screen_Width-45,[piece center].y + translation.y)];

[panGes setTranslation:CGPointZero inView:[piece superview]];

}

if (([piece center].y + translation.y)>Screen_Height-80) {

[piece setCenter:CGPointMake([piece center].x + translation.x,Screen_Height-80)];

[panGes setTranslation:CGPointZero inView:[piece superview]];

}

if (([piece center].y + translation.y)<80) {

[piece setCenter:CGPointMake([piece center].x + translation.x,80)];

[panGes setTranslation:CGPointZero inView:[piece superview]];

}

}];

}

}

}else{

if([self.skinView.playerLoadingView isLoading]==NO && self.video.isEnd==NO && [LPLejuUtility isCouldConnectedNet]){

self.fullScreen=YES;

[super pan:panGes];

}

}

}

- (void)tapGestureHandler:(id)sender

{

if([self skinView].inChatMode)

{

if([self skinView].inVoiceRecordMode)

{

return;

}

if ([[[UIDevice currentDevice] systemVersion] intValue] < 6)

{

UITapGestureRecognizer *ges = (UITapGestureRecognizer*)sender;

CGPoint point = [ges locationInView:self.view];

UIView* result = [ges.view hitTest:point withEvent:nil];

if(result.frame.size.height < ges.view.frame.size.height)

{

return;

}

}

[self skinView].inChatMode = NO;

return;

}

}

@end

```

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子勋篓,更是在濱河造成了極大的恐慌,老刑警劉巖菇用,帶你破解...
    沈念sama閱讀 216,496評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件肩碟,死亡現(xiàn)場離奇詭異贸辈,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)碰逸,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,407評論 3 392
  • 文/潘曉璐 我一進(jìn)店門乡小,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人饵史,你說我怎么就攤上這事劲件。” “怎么了约急?”我有些...
    開封第一講書人閱讀 162,632評論 0 353
  • 文/不壞的土叔 我叫張陵零远,是天一觀的道長。 經(jīng)常有香客問我厌蔽,道長牵辣,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,180評論 1 292
  • 正文 為了忘掉前任奴饮,我火速辦了婚禮纬向,結(jié)果婚禮上择浊,老公的妹妹穿的比我還像新娘。我一直安慰自己逾条,他們只是感情好琢岩,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,198評論 6 388
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著师脂,像睡著了一般担孔。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上吃警,一...
    開封第一講書人閱讀 51,165評論 1 299
  • 那天糕篇,我揣著相機(jī)與錄音,去河邊找鬼酌心。 笑死拌消,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的安券。 我是一名探鬼主播墩崩,決...
    沈念sama閱讀 40,052評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼侯勉!你這毒婦竟也來了泰鸡?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,910評論 0 274
  • 序言:老撾萬榮一對情侶失蹤壳鹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后饰迹,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體芳誓,經(jīng)...
    沈念sama閱讀 45,324評論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,542評論 2 332
  • 正文 我和宋清朗相戀三年啊鸭,在試婚紗的時候發(fā)現(xiàn)自己被綠了锹淌。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,711評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡赠制,死狀恐怖赂摆,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情钟些,我是刑警寧澤烟号,帶...
    沈念sama閱讀 35,424評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站政恍,受9級特大地震影響汪拥,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜篙耗,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,017評論 3 326
  • 文/蒙蒙 一迫筑、第九天 我趴在偏房一處隱蔽的房頂上張望宪赶。 院中可真熱鬧,春花似錦脯燃、人聲如沸搂妻。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,668評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽欲主。三九已至,卻和暖如春坟募,著一層夾襖步出監(jiān)牢的瞬間岛蚤,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,823評論 1 269
  • 我被黑心中介騙來泰國打工懈糯, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留涤妒,地道東北人。 一個月前我還...
    沈念sama閱讀 47,722評論 2 368
  • 正文 我出身青樓赚哗,卻偏偏與公主長得像她紫,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子屿储,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,611評論 2 353

推薦閱讀更多精彩內(nèi)容