自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

IOS實(shí)例 CALayer層動畫點(diǎn)擊

移動開發(fā) iOS
本文介紹的IOS實(shí)例 CALayer層動畫點(diǎn)擊,CALayer在運(yùn)動過程中,需要點(diǎn)擊CALayer,同時能夠監(jiān)控到點(diǎn)擊的對象,來看具體內(nèi)容。

IOS實(shí)例 CALayer動畫點(diǎn)擊是本文要介紹的內(nèi)容,利用CALayer可以實(shí)現(xiàn)復(fù)雜的動畫效果,同時CALayer在運(yùn)動過程中,需要點(diǎn)擊CALayer,同時能夠監(jiān)控到點(diǎn)擊的對象。下面是實(shí)現(xiàn)的效果和過程。如圖所示:

IOS實(shí)例 CALayer層動畫點(diǎn)擊

實(shí)現(xiàn)過程:

  1. #import "AnimView.h"   
  2. @implementation AnimView  
  3.  
  4. - (id)initWithFrame:(CGRect)frame {   
  5.       
  6.     self = [super initWithFrame:frame];   
  7.     if (self) {   
  8.         [self setBackgroundColor:[UIColor clearColor]];   
  9.         UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchesPoint:)];   
  10.         [self addGestureRecognizer:tapGesture];   
  11.         [tapGesture release];   
  12.     }   
  13.     return self;   
  14. }   
  15. -(void) drawRect:(CGRect)rect   
  16. {   
  17.     [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(stratAnim:) userInfo:nil repeats: NO];   
  18. }   
  19. -(void)stratAnim:(id)sender   
  20. {   
  21.     //添加層   
  22.     layer2 = [CALayer layer];   
  23.     [layer2 setBackgroundColor:[[UIColor redColor] CGColor]];   
  24.     layer2.bounds = CGRectMake(0, 0, 60,40);//層設(shè)置為圖片大小   
  25.     layer2.position = CGPointMake(25,25);//層在view的位置   
  26.     [self.layer addSublayer:layer2];//將層加到當(dāng)前View的默認(rèn)layer下   
  27.       
  28.     [self startFlyStarAnimation];   
  29. }   
  30. -(void) startFlyStarAnimation   
  31. {      
  32.     //運(yùn)動軌跡   
  33.     CGMutablePathRef thePath=CGPathCreateMutable();   
  34.     CGPathMoveToPoint(thePath,NULL,self.center.x,self.center.y);   
  35.     CGPathAddLineToPoint(thePath, NULL, self.center.x, self.center.y-45);   
  36.     CGPathAddLineToPoint(thePath, NULL, self.center.x, self.center.y+45);   
  37.     CGPathAddLineToPoint(thePath, NULL, self.center.x, self.center.y);   
  38.       
  39.     //添加動畫   
  40.     CAKeyframeAnimation * animation;   
  41.     animation=[CAKeyframeAnimation animationWithKeyPath:@"position"];   
  42.     animation.path=thePath;   
  43.     animation.duration=3.0;   
  44.     animation.repeatCount=2;   
  45.     CFRelease(thePath);   
  46.     [animation setDelegate:self];   
  47.     //[self animationDidStop:animation finished:YES];   
  48.     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];   
  49.     [layer2 addAnimation:animation forKey:kCATransition];   
  50. }   
  51. //動畫停止   
  52. -(void) animationDidStop:(CAAnimation *)anim finished:(BOOL)flag   
  53. {   
  54.     NSLog(@">>>>動畫停止了");   
  55. }   
  56. //touch事件   
  57. -(void)touchesPoint:(UITapGestureRecognizer *)gestureRecognizer   
  58. {   
  59.     CGPoint locationInView = [gestureRecognizer locationInView:self];   
  60.     //presentationLayer layer的動畫層   
  61.    CALayer *layer1=[[layer2 presentationLayer] hitTest:locationInView];   
  62.     if (layer1!=nil) {   
  63.         NSLog(@"點(diǎn)擊了運(yùn)動的layer");   
  64.     }   
  65. }   
  66. - (void)dealloc {   
  67.     [super dealloc];   
  68. }   
  69. @end  

其中presentationLayer是CALayer動畫的位置層。

源代碼:http://easymorse-iphone.googlecode.com/svn/trunk/iphone.presentlayer/

小結(jié):IOS實(shí)例 CALayer動畫點(diǎn)擊的內(nèi)容介紹完了,希望本文對你有所幫助!

責(zé)任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-07-22 18:20:04

IOS View 動畫

2015-03-24 09:37:50

SwiftiOSCALayer

2012-12-24 13:38:01

iOSUIView

2015-06-18 10:33:02

iOS粘性動畫

2009-06-29 14:21:00

無線網(wǎng)絡(luò)家庭組網(wǎng)

2011-07-03 10:05:52

Core Animat

2011-08-09 17:16:56

CoreAnimati動畫

2011-05-11 10:28:03

2015-07-27 10:27:32

IOS基礎(chǔ)知識核心動畫

2015-12-30 14:16:05

iOS動畫視圖渲染

2015-12-23 09:16:33

ios動畫渲染機(jī)制

2011-07-26 15:56:53

iPhone 游戲 啟動畫面

2011-07-18 16:57:36

Core Animation 動畫

2011-06-24 16:09:24

Qt 動畫 狀態(tài)機(jī)

2013-07-29 05:01:31

iOS開發(fā)iOS開發(fā)學(xué)習(xí)按鈕拖動和點(diǎn)擊

2009-07-28 15:08:50

MVC三層架構(gòu)實(shí)例

2010-09-14 14:42:24

FlashDIV CSS

2011-07-22 16:47:53

iOS 通知 xcode

2011-07-26 11:08:23

iOS 錄像 錄音

2009-10-29 17:17:01

接入層技術(shù)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號