ios開發仿寫微信視頻聊天界面

自己開發時需求要求,就自己開發了一個,個人思路:

1、創建View放在window上

self = [super initWithFrame:CGRectMake(0,  SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.backgroundColor = [UIColor purpleColor];
    id <UIApplicationDelegate> delegate = [[UIApplication sharedApplication] delegate];
    if ([delegate respondsToSelector:@selector(window)])
    {
        self.window = [delegate performSelector:@selector(window)];
    }
    else
    {
        self.window = [[UIApplication sharedApplication] keyWindow];
    }
    [self.window addSubview:self];

2、添加拖拽和顯示手勢

 UIPanGestureRecognizer *gesture = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panGestureRecognizer:)];
    gesture.delegate = self;
    [self addGestureRecognizer:gesture];
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestureRecognizer:)];
    [self addGestureRecognizer:tapGesture];
    [UIView setAnimationsEnabled:YES];

3、顯示View

-(void)show
{
       CGRect frame = self.frame;
        frame.origin.y = 0;

        [UIView animateWithDuration:0.4 animations:^{
            self.frame = frame;
        }];
}

4、實現拖拽手勢

-(void)panGestureRecognizer:(UIPanGestureRecognizer *)recognizer
{
    if (!self.isSclae)
    {
        return;
    }
    CGPoint point = [recognizer translationInView:recognizer.view.superview];
    CGPoint center = CGPointMake(recognizer.view.center.x + point.x,recognizer.view.center.y + point.y);
    if (center.x > SCREEN_WIDTH - recognizer.view.frame.size.width/2)
    {
        center.x = SCREEN_WIDTH - recognizer.view.frame.size.width/2;
    }
    else if (center.x < recognizer.view.frame.size.width/2)
    {
        center.x = recognizer.view.frame.size.width/2;
    }
    else if (center.y < recognizer.view.frame.size.width/2)
    {
        center.y = recognizer.view.frame.size.width/2;
    }
    else if (center.y > SCREEN_HEIGHT - recognizer.view.frame.size.width/2)
    {
        center.y = SCREEN_HEIGHT - recognizer.view.frame.size.width/2;
    }
    [UIView animateWithDuration:0.1 animations:^{
        recognizer.view.center = center;
        [recognizer setTranslation:CGPointZero inView:recognizer.view.superview];
    } completion:^(BOOL finished) {
        _lastPointX = center.x - recognizer.view.frame.size.width/2;
        _lastPointY = center.y - recognizer.view.frame.size.height/2;
    }];
}

5、實現點擊放大的手勢

-(void)tapGestureRecognizer:(UITapGestureRecognizer *)recognizer
{
    [self.window bringSubviewToFront:self];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"ScaleBig" object:nil];
    CGRect frame = self.frame;
    frame.origin.y = 0;
    frame.origin.x = 0;
    frame.size.width = SCREEN_WIDTH;
    frame.size.height = SCREEN_HEIGHT;
    [UIView animateWithDuration:0.2 animations:^{
        self.frame = frame;
    } completion:^(BOOL finished) {
        self.isSclae = NO;

    }];
}

6、取消移動

-(void)hidden
{
    CGRect frame = self.frame;
    frame.origin.y = SCREEN_HEIGHT;

    [UIView animateWithDuration:0.5 animations:^{
        self.frame = frame;
    }completion:^(BOOL finished) {
        self.isSclae = NO;
        [self removeFromSuperview];
    }];
}

7、(1)效果圖1
這裏寫圖片描述

(2)效果圖2
這裏寫圖片描述
(3)效果圖3
這裏寫圖片描述

發佈了35 篇原創文章 · 獲贊 10 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章