zoukankan      html  css  js  c++  java
  • iOS长按控件

    前言

    网上看到一个button的长按控件效果不错,一个菱形从中间向两边增大,研究了下

    原理

    上图红色是控件上面放了视图,从上到下分别是view,normalLable,highlightLabel,button

    其中View是顺时针旋转了45度

    通过点击控件触发里面的按钮的监听事件 

    按下没有松手:增大view的高度,改变两个label的透明度

    抬起 :缩小view的高度,改变两个label的透明度

    后面设置超出父视图不显示就可以把多余的黑色隐藏了,实现了中心向外面扩散

    部分代码:

    长按监听

     1 - (void)buttonTouchDownAndDragEnter {
     2     NSLog(@"长按不松");
     3     
     4     [self removeShowViewAndLabelLayer];
     5     [UIView animateWithDuration:(self.toEndDuration <= 0 ? TIME_END_DURATION : self.toEndDuration)
     6                      animations:^{
     7                          [self showShowView];
     8                      } completion:^(BOOL finished) {
     9                          if (finished == YES) {
    10                              self.isEND = YES;
    11                          }
    12                      }];
    13 }

    部分方法

    - (void)showShowView {
        self.showView.bounds = CGRectMake(0, 0, SHOW_VIEW_WIDTH,
                                          (self.animationWidth <= 0? SHOW_VIEW_WIDTH : self.animationWidth));
        self.showView.alpha  = 1;
        
        self.normalLabel.alpha    = 0.f;
        self.highlightLabel.alpha = 1.f;
        
    }
    
    //隐藏showView,改变普通和高亮状态
    
    - (void)hiddenShowView {
        self.showView.bounds = CGRectMake(0, 0, SHOW_VIEW_WIDTH, 0);
        self.showView.alpha  = 0;
        
        self.normalLabel.alpha    = 1.f;
        self.highlightLabel.alpha = 0.f;
        
    }
    
    //移除之前的动画
    - (void)removeShowViewAndLabelLayer {
        self.showView.bounds = ((CALayer *)self.showView.layer.presentationLayer).bounds;
        self.showView.alpha  = ((CALayer *)self.showView.layer.presentationLayer).opacity;
        
        self.normalLabel.alpha    = ((CALayer *)self.normalLabel.layer.presentationLayer).opacity;
        self.highlightLabel.alpha = ((CALayer *)self.highlightLabel.layer.presentationLayer).opacity;
        
        // 移除之前的动画状态
        [self.showView.layer removeAllAnimations];
    }

    demo链接:http://pan.baidu.com/s/1eRckm4q

  • 相关阅读:
    WEB服务器防盗链_HttpAccessKeyModule_Referer(Nginx&&PHP)
    子查询2
    子查询
    接上篇elasticsecrchi 进行搜索及时提示,数据库以及后台代码
    Django项目之【学员管理系统】
    Django 请求生命周期【图示】
    Django 之一些request封装的常用功能
    Django 认证系统 cookie & session & auth模块
    Django 模型系统(model)&ORM--进阶
    Django 模型系统(model)&ORM--基础
  • 原文地址:https://www.cnblogs.com/hxwj/p/5027919.html
Copyright © 2011-2022 走看看