国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

iOS手勢

2019-11-14 17:53:36
字體:
供稿:網(wǎng)友

手勢

定義

  1. 為了完成手勢識(shí)別,必須借助于手勢識(shí)別器----UIGestureRecognizer
    2. 利用UIGestureRecognizer,能識(shí)別用戶在某個(gè)view上做的一些常見手勢
    3. UIGestureRecognizer是一個(gè)抽象類,定義了所有手勢的基本行為,使用它的子類才能處理具體的手勢

  • UITapGestureRecognizer(敲擊)

  • UipinchGestureRecognizer(縮放)

  • UIRotationGestureRecognizer(旋轉(zhuǎn))

  • UISwipeGestureRecognizer(輕掃)

  • UIPanGestureRecognizer(拖拽)

  • UIScreenEdgePanGestureRecognizer

  • UILongPRessGestureRecognizer(長按)

#import "ViewController.h"@interface ViewController ()<UIGestureRecognizerDelegate>@property (weak, nonatomic) IBOutlet UIView *iconView;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];#warning 要實(shí)現(xiàn)手勢操作userInteractionEnabled必須設(shè)為YES;    // 1.旋轉(zhuǎn)手勢//    [self testRotate];        // 2.捏合手勢//    [self testPinch];        // 3.同時(shí)進(jìn)行捏合和旋轉(zhuǎn)    // 同時(shí)進(jìn)行捏合和旋轉(zhuǎn)需要實(shí)現(xiàn)代理方法//    [self testPinchAndRotate];        // 4.測試拖拽    [self testPan];    }#pragma mark - 拖拽手勢- (void)testPan{    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panView:)];        [_iconView addGestureRecognizer:pan];    }/** *  拖拽手勢 */- (void)panView:(UIPanGestureRecognizer *)pan{    UIView *panView = pan.view; // 被拖拽的view        //1.view上移動(dòng)的位置    CGPoint translation = [pan translationInView:panView];  // 在view上拖拽的位置    CGPoint center = panView.center;    center.x += translation.x;    center.y += translation.y;    panView.center = center;        // 2.清空移動(dòng)的位置    [pan setTranslation:CGPointZero inView:panView];}#pragma mark - 代理方法- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{    return YES;}#pragma mark - 旋轉(zhuǎn)和縮放- (void)testPinchAndRotate{    [self testPinch];        [self testRotate];}#pragma mark - 縮放手勢- (void)testPinch{    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];#warning 如果只是實(shí)現(xiàn)單個(gè)縮放手勢可以不用實(shí)現(xiàn)代理方法    pinch.delegate = self;        [_iconView addGestureRecognizer:pinch];}/** *  捏合 */- (void)pinch:(UIPinchGestureRecognizer *)pinch{    pinch.view.transform = CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale);    pinch.scale = 1;    // 可以認(rèn)為每次捏合后縮放的比例都重新重置為1}#pragma mark - 旋轉(zhuǎn)手勢- (void)testRotate{    UIRotationGestureRecognizer *rotate = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];    [_iconView addGestureRecognizer:rotate];}/** *  旋轉(zhuǎn) */- (void)rotate:(UIRotationGestureRecognizer *)rotate{    rotate.view.transform = CGAffineTransformRotate(rotate.view.transform, rotate.rotation);    rotate.rotation = 0;    // 每次旋轉(zhuǎn)后旋轉(zhuǎn)的角度重置為0}@end

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 句容市| 芦山县| 万宁市| 保定市| 鄱阳县| 修武县| 铜梁县| 铅山县| 荣昌县| 水富县| 塔城市| 龙井市| 沾益县| 青川县| 武隆县| 万安县| 兴安盟| 丰原市| 荔浦县| 江阴市| 昌黎县| 揭东县| 阳泉市| 改则县| 铜川市| 乌拉特前旗| 来凤县| 平定县| 读书| 喀喇| 岑巩县| 许昌县| 虹口区| 兴和县| 七台河市| 芦溪县| 盐边县| 定州市| 侯马市| 全南县| 涟水县|