iOS長按控制項,iOS長控制項

來源:互聯網
上載者:User

iOS長按控制項,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

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.