UI中的手勢部分

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    //給view添加一個背景顏色

    self.view.backgroundColor = [UIColor redColor];

 

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 335, 500)];

    imageView.backgroundColor = [UIColor cyanColor];

    [self.view addSubview:imageView];

    [imageView release];

//    //產生一個UIImage對象

//    

//    //通過圖片名字, 創建

//    UIImage *image = [UIImage imageNamed:@"i.jpg"];

//    

//    imageView.image = image;

//    

    

    //通過圖片路徑, 創建

    

    //獲取在工程文件列表中的圖片路徑

    NSString *path = [[NSBundle mainBundle] pathForResource:@"i" ofType:@"jpg"];

    

    UIImage *image1 = [UIImage imageWithContentsOfFile:path];

    

    imageView.image = image1;

    //設置imageView, 讓其能夠響應用戶交互

    imageView.userInteractionEnabled = YES;

    

    //手勢,需要哪個手勢就把哪部分註釋解開  

//    //1.輕拍  Tap

//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];

//    

//    //觸發這個方法的時候點擊的次數

//    tap.numberOfTapsRequired = 2;

//    

//    //需要幾個手指點擊

//    tap.numberOfTouchesRequired = 2;

//    

//    [imageView addGestureRecognizer:tap];

//    

//    [tap release];

    

//    //2.平移 pan

//    

//    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];

//    

//    [imageView addGestureRecognizer:pan];

//    [pan release];


//    //3.縮放 pinch

//    

//    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];

//    [imageView addGestureRecognizer:pinch];

//    [pinch release];


    

    

//    //4.旋轉 rotation

//    UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAction:)];

//    

//    [imageView addGestureRecognizer:rotation];

//    [rotation release];

//    

    

    

//    //5.輕掃 swipe

//    

//    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];

//    

//    //swipe的方向, 默認方向是向右

//    swipe.direction = UISwipeGestureRecognizerDirectionLeft;

//    

//    

//    [imageView addGestureRecognizer:swipe];

//    [swipe release];

    

    

    

    //6.長按 longPress

//    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];

//    

//    //規定爲長安手勢 需要的時間, 默認是0.5

//    longPress.minimumPressDuration = 3;

//    

//    //規定用戶長按可移動的距離,默認是10

//    longPress.allowableMovement = 100;

//    

//    [imageView addGestureRecognizer:longPress];

//    [longPress release];

    

    

    //7.屏幕邊緣平移

    

    

    UIScreenEdgePanGestureRecognizer *screen = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(screenAction:)];

    

    

    [imageView addGestureRecognizer:screen];

    [screen release];


    

}

//

////輕拍的方法

//- (void)tapAction:(UITapGestureRecognizer *)tap

//{

//    NSLog(@"輕拍");

//}


////長按的方法

//- (void)longPressAction:(UILongPressGestureRecognizer *)longPress

//{

//    //手勢的狀態

//    

//    if (longPress.state == UIGestureRecognizerStateBegan) {

//        //當手勢的狀態處於剛開始的狀態

//        

//        NSLog(@"長按");

//    }

//    

//}

//

////輕掃的方法

//- (void)swipeAction:(UISwipeGestureRecognizer *)swipe

//{

//    //可以通過手勢的view屬性 直接獲取手勢所在的view

//    UIImageView *imageView = (UIImageView *)swipe.view;

//    

//    imageView.image = [UIImage imageNamed:@"71b1OOOPICb8.jpg"];

//    

//    

//    NSLog(@"輕掃");

//}




////旋轉的方法

//- (void)rotationAction:(UIRotationGestureRecognizer *)rot;

//{

//    NSLog(@"旋轉");

//    //view跟着手勢旋轉

//    

//    rot.view.transform = CGAffineTransformRotate(rot.view.transform, rot.rotation);

//    //重置弧度

//    rot.rotation = 0;

//    

//    

//}




////縮放的方法

//- (void)pinchAction:(UIPinchGestureRecognizer *)pinch;

//{

//    NSLog(@"縮放");

//    

//    pinch.view.transform = CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale);

//    

//    

//    

//}



////平移的方法

//- (void)panAction:(UIPanGestureRecognizer *)pan;

//{

//    NSLog(@"平移");

//    

//    CGPoint point = [pan translationInView:pan.view];

//    pan.view.transform = CGAffineTransformTranslate(pan.view.transform, point.x, point.y);

//    [pan setTranslation:CGPointZero inView:pan.view];

//

//

//}



//手勢的方法

- (void)screenAction:(UIScreenEdgePanGestureRecognizer *)screen

{

    NSLog(@"手勢");

}





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章