中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

iOS簡易抽屜效果

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
直接在controller里面加代碼實現(xiàn)的抽屜效果
@interface ViewController () {
    UIView* _leftView;
}
 
@end
 
@implementation ViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
     
    _leftView = [[UIView alloc] init];
    //把左側(cè)邊的view先隱藏
    _leftView.frame = CGRectMake(-200, 0, 200, self.view.frame.size.height);
    _leftView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:_leftView];
     
    UIPanGestureRecognizer* pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
    [self.view addGestureRecognizer:pan];
}
 
- (void)handlePan:(UIPanGestureRecognizer*) recognizer {
    CGPoint translation = [recognizer translationInView:self.view];
    //增量后的x坐標(biāo)位置
    CGFloat Xresult = translation.x + _leftView.frame.origin.x;
     
    //向右
    if (translation.x >= 0) {
        //leftView已全部拉出,則無法再向右
        if (_leftView.frame.origin.x >= 0 || Xresult >= 0) {
            _leftView.frame = CGRectMake(0, 0, 200, self.view.frame.size.height);
             
            return;
        }
    } else if (translation.x < 0) {//向左
        //leftView已全部收回,則無法再向左
        if (_leftView.frame.origin.x <= -200 || Xresult <= -200) {
            _leftView.frame = CGRectMake(-200, 0, 200, self.view.frame.size.height);
            return;
        }
    }
     
    CGRect frame = _leftView.frame;
    frame.origin.x += translation.x;
    _leftView.frame = frame;
     
    //清空移動的距離,這是關(guān)鍵
    [recognizer setTranslation:CGPointZero inView:recognizer.view];
     
    //做彈回效果,以中軸為界限
    if (recognizer.state == UIGestureRecognizerStateEnded) {
        if (_leftView.frame.origin.x > -100) {
            [self closeView:NO];
        } else {
            [self closeView:YES];
        }
    }
}
 
- (void)closeView:(BOOL)close {
    if (close) {
        [self moveView:CGRectMake(-200, 0, 200, self.view.frame.size.height)];
    } else {
        [self moveView:CGRectMake(0, 0, 200, self.view.frame.size.height)];
    }
}
 
- (void)moveView:(CGRect)frame {
    [UIView animateWithDuration:0.3 animations:^{
        _leftView.frame = frame;
    } completion:^(BOOL finished) {
         
    }];
}

標(biāo)簽: 代碼

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:C#獲得機器的Mac地址

下一篇:一個用于生成驗證碼的C#類代碼