美文网首页
仿直播频道切换页面的实现

仿直播频道切换页面的实现

作者: TikBai | 来源:发表于2017-03-18 09:44 被阅读0次

#import "LivingInfoView.h"

#define Screen_width [UIScreen mainScreen].bounds.size.width

#define Screen_height [UIScreen mainScreen].bounds.size.height

@interface ViewController ()

@property (weak, nonatomic) LivingInfoView *livingInfoView;

@property (assign, nonatomic) BOOL isBeginSlid;//记录开始触摸的方向

@property (weak, nonatomic) UIImageView *playLayer;

@end


- (void)viewDidLoad {

[super viewDidLoad];

self.view.backgroundColor = [UIColor whiteColor];

//    播放层

UIImageView *playLayer = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, Screen_width, Screen_height)];

[self.view addSubview:playLayer];

self.playLayer = playLayer;

playLayer.image = [UIImage imageNamed:@"123.jpeg"];

playLayer.userInteractionEnabled = YES;

//    播放信息层

LivingInfoView *livingInfoView = [[LivingInfoView alloc]initWithFrame:CGRectMake(0, 0, Screen_width, Screen_height)];

[playLayer addSubview:livingInfoView];

self.livingInfoView = livingInfoView;

livingInfoView.backgroundColor = [UIColor colorWithRed:242 / 255.0 green:156 / 255.0 blue:177 / 255.0 alpha:0.6];

// Do any additional setup after loading the view, typically from a nib.

}


#pragma mark - 界面的滑动- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event {

self.isBeginSlid = YES;

}


- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent *)event {

//    1.获取手指

UITouch *touch = [touches anyObject];

//    2.获取触摸的上一个位置

CGPoint lastPoint;

CGPoint currentPoint;

//    3.获取偏移位置

CGPoint tempCenter;

if (self.isBeginSlid) {//首次触摸进入

lastPoint = [touch previousLocationInView:self.playLayer];

currentPoint = [touch locationInView:self.playLayer];

//判断是左右滑动还是上下滑动

if (ABS(currentPoint.x - lastPoint.x) > ABS(currentPoint.y - lastPoint.y)) {

//    3.获取偏移位置

tempCenter = self.livingInfoView.center;

tempCenter.x += currentPoint.x - lastPoint.x;//左右滑动

//禁止向左划

if (self.livingInfoView.frame.origin.x == 0 && currentPoint.x -lastPoint.x > 0) {//滑动开始是从0点开始的,并且是向右滑动

self.livingInfoView.center = tempCenter;

}

//            else if(self.livingInfoView.frame.origin.x > 0){

//                self.livingInfoView.center = tempCenter;

//            }

//            NSLog(@"%@-----%@",NSStringFromCGPoint(tempCenter),NSStringFromCGPoint(self.livingInfoView.center));

}else{

//    3.获取偏移位置

tempCenter = self.playLayer.center;

tempCenter.y += currentPoint.y - lastPoint.y;//上下滑动

self.playLayer.center = tempCenter;

}

}else{//滑动开始后进入,滑动方向要么水平要么垂直

if (self.playLayer.frame.origin.y != 0){//垂直的优先级高于左右滑,因为左右滑的判定是不等于0

lastPoint = [touch previousLocationInView:self.playLayer];

currentPoint = [touch locationInView:self.playLayer];

tempCenter = self.playLayer.center;

tempCenter.y += currentPoint.y -lastPoint.y;

self.playLayer.center = tempCenter;

}else if (self.livingInfoView.frame.origin.x != 0) {

lastPoint = [touch previousLocationInView:self.livingInfoView];

currentPoint = [touch locationInView:self.livingInfoView];

tempCenter = self.livingInfoView.center;

tempCenter.x += currentPoint.x -lastPoint.x;

//禁止向左划

if (self.livingInfoView.frame.origin.x == 0 && currentPoint.x -lastPoint.x > 0) {//滑动开始是从0点开始的,并且是向右滑动

self.livingInfoView.center = tempCenter;

}else if(self.livingInfoView.frame.origin.x > 0){

self.livingInfoView.center = tempCenter;

}

}

}

self.isBeginSlid = NO;

}


- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent *)event {

//    NSLog(@"%.2f-----%.2f",livingInfoView.frame.origin.y,Screen_height * 0.8);

//    水平滑动判断

//在控制器这边滑动判断如果滑动范围没有超过屏幕的十分之八livingInfoView还是离开屏幕

if (self.livingInfoView.frame.origin.x > Screen_width * 0.8) {

[UIView animateWithDuration:0.06 animations:^{

CGRect frame = self.livingInfoView.frame;

frame.origin.x = Screen_width;

self.livingInfoView.frame = frame;

}];

}else{//否则则回到屏幕0点

[UIView animateWithDuration:0.2 animations:^{

CGRect frame = self.livingInfoView.frame;

frame.origin.x = 0;

self.livingInfoView.frame = frame;

}];

}

//    上下滑动判断

if (self.playLayer.frame.origin.y > Screen_height * 0.2) {

//        切换到下一频道

self.playLayer.image = [UIImage imageNamed:@"PlayView2"];

}else if (self.playLayer.frame.origin.y < - Screen_height * 0.2){

//        切换到上一频道

self.playLayer.image = [UIImage imageNamed:@"PlayView"];

}

//        回到原始位置等待界面重新加载

CGRect frame = self.playLayer.frame;

frame.origin.y = 0;

self.playLayer.frame = frame;

}


- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent *)event{

//    水平滑动判断

//在控制器这边滑动判断如果滑动范围没有超过屏幕的十分之八livingInfoView还是离开屏幕

if (self.livingInfoView.frame.origin.x > Screen_width * 0.8) {

[UIView animateWithDuration:0.06 animations:^{

CGRect frame = self.livingInfoView.frame;

frame.origin.x = Screen_width;

self.livingInfoView.frame = frame;

}];

}else{//否则则回到屏幕0点

[UIView animateWithDuration:0.2 animations:^{

CGRect frame = self.livingInfoView.frame;

frame.origin.x = 0;

self.livingInfoView.frame = frame;

}];

}

//    上下滑动判断

if (self.livingInfoView.frame.origin.y > Screen_height * 0.2) {

//        切换到下一频道,重新加载界面,这里用切换图片做演示。

self.livingInfoView.backgroundColor

= [UIColor colorWithRed:arc4random_uniform(256) / 255.0

green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) /

255.0 alpha:0.5];

}else if (self.livingInfoView.frame.origin.y < - Screen_height * 0.2){

//        切换到上一频道,重新加载界面,这里用切换图片做演示。

self.livingInfoView.backgroundColor

= [UIColor colorWithRed:arc4random_uniform(256) / 255.0

green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) /

255.0 alpha:0.5];

}

//        回到原始位置等待界面重新加载

CGRect frame = self.livingInfoView.frame;

frame.origin.y = 0;

self.livingInfoView.frame = frame;

}

相关文章

  • 仿直播频道切换页面的实现

    #import "LivingInfoView.h" #define Screen_width [UIScreen...

  • 源码推荐:仿写映客直播 iOS快速切换主题

    源码推荐:仿写映客直播 iOS快速切换主题 源码推荐:仿写映客直播 iOS快速切换主题

  • 做视频直播时,如何实现多个场景的切换直播效果?

    做视频直播时,如何实现多个场景的切换直播效果?下面来说说如何实现切换吧。 场景切换:POLYV直播助手提供三个画面...

  • iOS直播界面的上下左右滑动效果

    我们看现在主流的直播平台都有左右滑动去掉直播信息,上下滑动切换频道的功能:粉色界面代表直播信息界面,就是观众、礼物...

  • Android仿抖音上下滑动切换视频

    Android仿抖音上下滑动切换视频  自从各大直播平台可以滑动切换直播间后,公司就出了一大波需求,还要配合各种收...

  • 2018-08-16使用router-view同页面加载多路由

    描述:用路由方式实现单页面加载多页面,并且切换页面后状态还是保存的,类似于单页面实现标签页,切换标签页实现内容显示...

  • 切换频道

    几天前,一朋友分享她的育儿经:“当我们正在做一件事情,别人提出来一起参与另外一件事情时,我们的大脑需要一点时间...

  • 频道切换

    · 频道,在这里所说的是我们的生活环境,也是我们心智模式。我们在一年之中或者一辈子中的某个时间段,会在某个地方生活...

  • 切换频道

    切换频道,主动收入赛道和被动收入赛道互切;业余创业同时补给主业的知识和能量。 突然想到投资的风险问题: 选择了没有...

  • 切换频道

    闹钟的音乐响了,新的一天开始了。 起床,做饭,每个动作是那么的娴熟而迅速。天气渐冷,厨房里的早晨让人觉得冷清。再想...

网友评论

      本文标题:仿直播频道切换页面的实现

      本文链接:https://www.haomeiwen.com/subject/jflunttx.html