iOS简易抽屉效果

iOS简易抽屉效果,第1张

概述iOS简易抽屉效果

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

直接在controller里面加代码实现的抽屉效果
@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];    //把左侧边的vIEw先隐藏    _leftVIEw.frame = CGRectMake(-200,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坐标位置    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,self.vIEw.frame.size.height);                         return;        }    } else if (translation.x < 0) {//向左        //leftVIEw已全部收回,则无法再向左        if (_leftVIEw.frame.origin.x <= -200 || Xresult <= -200) {            _leftVIEw.frame = CGRectMake(-200,self.vIEw.frame.size.height);            return;        }    }         CGRect frame = _leftVIEw.frame;    frame.origin.x += translation.x;    _leftVIEw.frame = frame;         //清空移动的距离,这是关键    [recognizer setTranslation:CGPointZero inVIEw:recognizer.vIEw];         //做d回效果,以中轴为界限    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,self.vIEw.frame.size.height)];    } else {        [self moveVIEw:CGRectMake(0,self.vIEw.frame.size.height)];    }} - (voID)moveVIEw:(CGRect)frame {    [UIVIEw animateWithDuration:0.3 animations:^{        _leftVIEw.frame = frame;    } completion:^(BOol finished) {             }];}

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的iOS简易抽屉效果全部内容,希望文章能够帮你解决iOS简易抽屉效果所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1106965.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存