iOS---給視圖添加手勢


 初始化手勢同時添加手勢事件---把手勢添加到視圖上

// 1.輕拍手勢類 // 創建一個輕拍手勢 同時綁定了一個事件 UITapGestureRecognizer *aTapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGRAction:)]; // 設置輕拍次數 aTapGR.numberOfTapsRequired = 1; // 設置手指觸摸的個數 aTapGR.numberOfTouchesRequired = 2; // 添加手勢 [self.rootView addGestureRecognizer:aTapGR]; [aTapGR release]; // 2.長按手勢 UILongPressGestureRecognizer *longPressGR = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)]; [self.rootView addGestureRecognizer:longPressGR]; [longPressGR release]; // 3.旋轉手勢 UIRotationGestureRecognizer *rotationGR = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAction:)]; [self.rootView.testImageView addGestureRecognizer:rotationGR]; [rotationGR release]; // 4.捏合手勢 UIPinchGestureRecognizer *pinchRG = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)]; [self.rootView addGestureRecognizer:pinchRG]; [pinchRG release]; // 5.平移手勢 UIPanGestureRecognizer *panGR = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGRAction:)]; [self.rootView.testImageView addGestureRecognizer:panGR]; [panGR release]; // 6.輕掃手勢 UISwipeGestureRecognizer *swipeGR = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGRAction:)]; // 設置滑動方向 默認是從左往右 swipeGR.direction = UISwipeGestureRecognizerDirectionLeft; // 設置向左滑動 [self.rootView.testImageView addGestureRecognizer:swipeGR]; [swipeGR release]; // 7.屏幕邊緣輕掃識別器 UIScreenEdgePanGestureRecognizer *screenPGR = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(screenEdgeGRAction:)]; [self.rootView addGestureRecognizer:screenPGR]; [screenPGR release];

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM