您好,登錄后才能下訂單哦!
- (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"]; //將用戶交互打開,,切記 只有兩個(gè)UIImage 和UILabel 都要打開交互 [p_w_picpathView setUserInteractionEnabled:YES]; [self.view addSubview:p_w_picpathView]; [p_w_picpathView release]; /* //手勢(shì)使用 看繼承關(guān)系,,,有沒有自己的初始化方法 //1.點(diǎn)擊 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)]; //1.1設(shè)置要點(diǎn)擊幾次才會(huì)觸發(fā)方法 tap.numberOfTapsRequired = 3; //1.2需要幾個(gè)手指點(diǎn)擊 tap.numberOfTouchesRequired = 2; //1.3將手勢(shì)添加到p_w_picpathView上 [p_w_picpathView addGestureRecognizer:tap]; [tap release]; */ /* //2.長(zhǎng)按 UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)]; //1.1判定為長(zhǎng)按手勢(shì)需要的最短時(shí)間 longPress.minimumPressDuration = 3; //1.2判定為長(zhǎng)按的過程中,允許用戶手指移動(dòng)的距離 longPress.allowableMovement = 300; [p_w_picpathView addGestureRecognizer:longPress]; [longPress release]; */ /* //3.旋轉(zhuǎn) 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]; //清掃的方向,向左 (如果要四個(gè)方向,就只能加四個(gè)手勢(shì)) 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; //獲得手勢(shì)經(jīng)過的點(diǎn) CGPoint p = [pan translationInView:view]; //對(duì)視圖的transform屬性改變 view.transform = CGAffineTransformTranslate(view.transform, p.x, p.y); //對(duì)拖拽的位置進(jìn)行初始化 [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); //捏合后重置 //在原有的基礎(chǔ)上在捏合 view.transform = CGAffineTransformScale(view.transform, pinch.scale, pinch.scale); pinch.scale = 1; NSLog(@"捏合"); } //3.旋轉(zhuǎn) - (void)rotationAction:(UIRotationGestureRecognizer *)rotation { //視圖的transform屬性---變形 //1.獲得添加手勢(shì)的視圖 UIImageView *p_w_picpathView = (UIImageView *)rotation.view; //2.旋轉(zhuǎn)的角度 (屬性,角度) p_w_picpathView.transform = CGAffineTransformRotate(p_w_picpathView.transform, rotation.rotation); rotation.rotation = 0; // NSLog(@"旋轉(zhuǎn)"); } //2.長(zhǎng)按 - (void)longPressAction:(UILongPressGestureRecognizer *)longPress { //長(zhǎng)按的方法在手勢(shì)的各個(gè)狀態(tài)都會(huì)觸發(fā),所以需要進(jìn)行判斷 // longPress.state if (longPress .state == UIGestureRecognizerStateBegan) { NSLog(@"長(zhǎng)按開始嘍噢!!"); }else if (longPress.state == UIGestureRecognizerStateEnded){ NSLog(@"長(zhǎng)按結(jié)束了呢!!"); } } //1.點(diǎn)擊點(diǎn)擊手勢(shì),的觸發(fā)方法 - (void)tapAction:(UITapGestureRecognizer *)tap { NSLog(@"快看,那是個(gè)塔!"); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。