zoukankan      html  css  js  c++  java
  • "长按实现视图抖动和删除"功能知识点整理

    一、功能细分

    1、对视图添加长按手势的识别:{ UILongPressGestureRecognizer类的使用}

    UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];

    longPressRecognizer.allowableMovement = 30;

    [testView addGestureRecognizer:longPressRecognizer];        

    [longPressRecognizer release];

     

     

    2、删除一个视图后,改变其它视图的位置,可以通过修改其center的值来实现:

    如 tempView.center = tempViewCenter;

     

    3、抖动的实现:{修改view的 transform值来改变视图的旋转过的角度;通过动画来实现动态角度转动;当动画结束后再时其转动相反角度,也动画实现,如此反复即可。}

    - (void)wobble {

    static BOOL wobblesLeft = NO;

    if (isShake) {

    CGFloat rotation = (kWobbleRadians * M_PI) / 180.0;

    CGAffineTransform wobbleLeft = CGAffineTransformMakeRotation(rotation);

    CGAffineTransform wobbleRight = CGAffineTransformMakeRotation(-rotation);

    [UIView beginAnimations:nil context:nil];

    NSInteger i = 0;

    NSInteger nWobblyButtons = 0;

    for (UIView *tempView in [scrollView subviews]) {

    if ([tempView isKindOfClass:[TestView class]] || [tempView isKindOfClass:[UIButton class]]) {

    ++nWobblyButtons;

    if (i % 2) {

    tempView.transform = wobblesLeft ? wobbleRight : wobbleLeft;

    } else {

    tempView.transform = wobblesLeft ? wobbleLeft : wobbleRight;

    }

    ++i;

    }

    }

    if (nWobblyButtons >= 1) {

    [UIView setAnimationDuration:kWobbleTime];

    [UIView setAnimationDelegate:self];

    [UIView setAnimationDidStopSelector:@selector(wobble)];

    wobblesLeft = !wobblesLeft;

    } else {

    [NSObject cancelPreviousPerformRequestsWithTarget:self];

    [self performSelector:@selector(wobble) withObject:nil afterDelay:kWobbleTime];

    }

    [UIView commitAnimations];

    }

    }

    4、停止抖动:

    tempView.transform = CGAffineTransformIdentity;

    二、知识点整理

    1、

    UIGestureRecognizer 手势识别类

    2、

    NSValue的使用

     

     

    3、

    CGAffineTransform

     

    CGFloat rotation = (kWobbleRadians * M_PI) / 180.0;

    CGAffineTransform wobbleLeft = CGAffineTransformMakeRotation(rotation);

    CGAffineTransform wobbleRight = CGAffineTransformMakeRotation(-rotation);

     

    tempView.transform = CGAffineTransformIdentity;

     

    4、UIView类中一些不常用到的内容

    如:uiview.transform

    5、NSObject类中一些不常用的内容

    如:[NSObject cancelPreviousPerformRequestsWithTarget:self];


    [self performSelector:@selector(wobble) withObject:nil afterDelay:kWobbleTime];

    6、NSTimer的使用

  • 相关阅读:
    160422、Highcharts后台获取数据
    160421、MyBatis批量插入数据
    微信小程序wx:for循环
    【小程序】获取到的e.target与e.currentTarget区别
    微信小程序如何像vue一样在动态绑定类名
    发布 Vant
    ZanUI-WeApp -- 一个颜值高、好用、易扩展的微信小程序 UI 库
    微信小程序 使用wxParse解析html
    精通移动端布局
    axios interceptors 拦截 , 页面跳转, token 验证 Vue+axios实现登陆拦截,axios封装(报错,鉴权,跳转,拦截,提示)
  • 原文地址:https://www.cnblogs.com/zhulin/p/2099896.html
Copyright © 2011-2022 走看看