首页 > 移动平台 > 详细

iOS长按控件

时间:2015-12-08 00:21:48      阅读:382      评论:0      收藏:0      [点我收藏+]

前言

网上看到一个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

 

iOS长按控件

原文:http://www.cnblogs.com/hxwj/p/5027919.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!