2013-03-25 98 views
0

我試圖放大和縮小的ImageView的縮放手勢不與ImageView的

在這裏工作是代碼

- (void)pinch:(UIPinchGestureRecognizer *)gesture 
{ 
    if (handSelected == YES) 
    { 
    if (gesture.state == UIGestureRecognizerStateEnded || gesture.state == UIGestureRecognizerStateChanged) 
    { 
     NSLog(@"gesture.scale = %f", gesture.scale); 

     CGFloat currentScale = self.imgHand.frame.size.width/self.imgHand.bounds.size.width; 
     CGFloat newScale = currentScale * gesture.scale; 

     if (newScale < 1.0) { 
      newScale = 1.0; 
     } 
     if (newScale > 4.0) { 
      newScale = 4.0; 
     } 

     CGAffineTransform transform = CGAffineTransformMakeScale(newScale, newScale); 
     self.imgHand.transform = transform; 
     gesture.scale = 1; 
    } 
    } 
} 


- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self adjustRingPressed:self]; 
    self.view.multipleTouchEnabled = YES; 
    self.imgHand.multipleTouchEnabled = YES; 
    UIPinchGestureRecognizer *gst = [[UIPinchGestureRecognizer alloc] initWithTarget:self.imgHand action:@selector(pinch:)]; 
    [gst setDelegate:self]; 
    [self.imgHand addGestureRecognizer:gst]; 

} 

看來我的捏代碼永遠不會運行

+0

嘗試設置目標自我並添加手勢識別到self.view – Marc 2013-03-25 13:35:47

回答

2

嘗試添加:

self.imgHand.userInteractionEnabled = TRUE; 

默認的UIImageView已userInteractionEnabled = FALSE

0

使它成爲一個功能的gesture像下面模板代碼:

- (IBAction)handlePinch:(UIPinchGestureRecognizer *)recognizer 
{ 
    recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale); 
    recognizer.scale = 1; 
}