- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. UIImageView *p_w_picpathView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 30, 280, 430)]; p_w_picpathView.p_w_picpath = [UIImage p_w_picpathNamed:@"2.jpg"]; //將用戶交互打開,,切記 只有兩個UIImage 和UILabel 都要打開交互 [p_w_picpathView setUserInteractionEnabled:YES]; [self.view addSubview:p_w_picpathView]; [p_w_picpathView release]; /* //手勢使用 看繼承關系,,,有沒有自己的初始化方法 //1.點擊 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)]; //1.1設置要點擊幾次才會觸發方法 tap.numberOfTapsRequired = 3; //1.2需要幾個手指點擊 tap.numberOfTouchesRequired = 2; //1.3將手勢添加到p_w_picpathView上 [p_w_picpathView addGestureRecognizer:tap]; [tap release]; */ /* //2.長按 UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)]; //1.1判定為長按手勢需要的最短時間 longPress.minimumPressDuration = 3; //1.2判定為長按的過程中,允許用戶手指移動的距離 longPress.allowableMovement = 300; [p_w_picpathView addGestureRecognizer:longPress]; [longPress release]; */ /* //3.旋轉 UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAction:)]; [p_w_picpathView addGestureRecognizer:rotation]; [rotation release]; */ /* //4.捏合 UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)]; [p_w_picpathView addGestureRecognizer:pinch]; [pinch release]; */ /* //5.拖拽 UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)]; [p_w_picpathView addGestureRecognizer:pan]; [pan release]; */ //6.清掃 UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(awipeAction:)]; [p_w_picpathView addGestureRecognizer:swipe]; //清掃的方向,向左 (如果要四個方向,就只能加四個手勢) swipe.direction = UISwipeGestureRecognizerDirectionLeft; [swipe release]; } //6.清掃 - (void)awipeAction:(UISwipeGestureRecognizer *)awipe { if (awipe.direction == UISwipeGestureRecognizerDirectionLeft) { NSLog(@"向左"); } NSLog(@"清掃"); } //5.拖拽 - (void)panAction:(UIPanGestureRecognizer *)pan { UIImageView *view = (UIImageView *)pan.view; //獲得手勢經過的點 CGPoint p = [pan translationInView:view]; //對視圖的transform屬性改變 view.transform = CGAffineTransformTranslate(view.transform, p.x, p.y); //對拖拽的位置進行初始化 [pan setTranslation:CGPointZero inView:view]; // NSLog(@"拖拽"); } //4.捏合 -(void)pinchAction:(UIPinchGestureRecognizer *)pinch { //試圖的TRanform屬性 UIImageView *view = (UIImageView *)pinch.view; //捏合的x,y的方向 // view.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale); //捏合后重置 //在原有的基礎上在捏合 view.transform = CGAffineTransformScale(view.transform, pinch.scale, pinch.scale); pinch.scale = 1; NSLog(@"捏合"); } //3.旋轉 - (void)rotationAction:(UIRotationGestureRecognizer *)rotation { //視圖的transform屬性---變形 //1.獲得添加手勢的視圖 UIImageView *p_w_picpathView = (UIImageView *)rotation.view; //2.旋轉的角度 (屬性,角度) p_w_picpathView.transform = CGAffineTransformRotate(p_w_picpathView.transform, rotation.rotation); rotation.rotation = 0; // NSLog(@"旋轉"); } //2.長按 - (void)longPressAction:(UILongPressGestureRecognizer *)longPress { //長按的方法在手勢的各個狀態都會觸發,所以需要進行判斷 // longPress.state if (longPress .state == UIGestureRecognizerStateBegan) { NSLog(@"長按開始嘍噢??!"); }else if (longPress.state == UIGestureRecognizerStateEnded){ NSLog(@"長按結束了呢??!"); } } //1.點擊點擊手勢,的觸發方法 - (void)tapAction:(UITapGestureRecognizer *)tap { NSLog(@"快看,那是個塔!"); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。