iOS长按控件

来源:互联网 时间:2015-12-08

前言

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

 

相关阅读:
Top