2011-08-11 12 views
4

試圖想出一個方法來做同樣的事情reeder應用程序的創建者在他的iphone/ipad應用程序與捏到展開照片全屏。捏像Reeder應用程序拍照全屏

我有一個表格單元格中的uiimageview,我想轉換到一個全屏視圖上捏打開,或者雙擊。也想使用類似的動畫。

任何提示將不勝感激!

回答

13

好吧,我設法把我自己放在一起。不太確定如何使用過渡方法,但我需要在同一位置複製視圖,然後將其解決。

http://screencast.com/t/MLTuGkIYh

所以在我的小區包含大圖像I掛鉤都捏,然後點擊手勢識別。

self.imageView.contentMode = UIViewContentModeScaleAspectFit; 
    self.imageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); 
    UIPinchGestureRecognizer *pinchGesture = [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)] autorelease]; 
    UITapGestureRecognizer *tapGesture = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)] autorelease]; 
    tapGesture.numberOfTapsRequired = 2; 
    self.imageView.userInteractionEnabled = YES; 
    self.imageView.multipleTouchEnabled = YES; 
    [self.imageView addGestureRecognizer:pinchGesture]; 
    [self.imageView addGestureRecognizer:tapGesture]; 
    [cell.contentView addSubview:self.imageView]; 

然後這裏是其餘的代碼。基本上,當我認識到手勢(並捏,確保它完成)我把重複的視圖在同一個確切的位置(通過convertRect東西獲得),然後動畫化其框架和背景顏色。從它返回時,我做相反的事。

- (void)handlePinchGesture:(id)sender 
{ 
    if (((UIPinchGestureRecognizer *)sender).state == UIGestureRecognizerStateEnded) { 
     if(((UIPinchGestureRecognizer *)sender).view == self.imageView) 
     { 
      if (((UIPinchGestureRecognizer *)sender).scale > 1) { 
       [self showFloorPlanFullScreen]; 
      } 
     } else { 
      if (((UIPinchGestureRecognizer *)sender).scale < 1) { 
       [self closeFloorPlanFullScreen]; 
      } 
     } 
    } 
} 
- (void)handleTap:(id)sender 
{ 
    if (((UITapGestureRecognizer *)sender).view == self.imageView) { 
     [self showFloorPlanFullScreen]; 
    } else { 
     [self closeFloorPlanFullScreen]; 
    } 
} 

- (void)showFloorPlanFullScreen 
{ 
    CGRect newRect = [self.imageView convertRect:self.imageView.bounds toView:[self.splitViewController.view superview]]; 
    UIImage *image = self.imageView.image; 
    self.fullScreenImageView = [[[UIImageView alloc] initWithImage:image] autorelease]; 

    UIPinchGestureRecognizer *pinchGesture = [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)] autorelease]; 
    UITapGestureRecognizer *tapGesture = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)] autorelease]; 
    tapGesture.numberOfTapsRequired = 2; 
    self.fullScreenImageView.userInteractionEnabled = YES; 
    self.fullScreenImageView.multipleTouchEnabled = YES; 
    [self.fullScreenImageView addGestureRecognizer:pinchGesture]; 
    [self.fullScreenImageView addGestureRecognizer:tapGesture]; 

    self.fullScreenImageView.contentMode = UIViewContentModeScaleAspectFit; 
    self.fullScreenImageView.frame = newRect; 
    self.fullScreenImageView.backgroundColor = [UIColor clearColor]; 
    [[self.splitViewController.view superview] addSubview:self.fullScreenImageView]; 

    CGRect splitViewRect = self.splitViewController.view.frame; 
    [UIView animateWithDuration:0.5 animations:^{ 
     self.fullScreenImageView.backgroundColor = [UIColor blackColor]; 
     self.fullScreenImageView.frame = splitViewRect; 
    }]; 
} 


- (void)closeFloorPlanFullScreen 
{ 
    CGRect newRect = [self.imageView convertRect:self.imageView.bounds toView:[self.splitViewController.view superview]]; 
    [UIView animateWithDuration:0.5 
        animations:^{ 
     self.fullScreenImageView.backgroundColor = [UIColor clearColor]; 
     self.fullScreenImageView.frame = newRect; 
        } 
        completion:^(BOOL finished) { 
         [self.fullScreenImageView removeFromSuperview]; 
         self.fullScreenImageView = nil; 
        }]; 
} 

如果你想要的圖片實際大小調整變焦時,我將盡快推薦添加重複的視圖作爲捏開始(只要它的縮放> 1),然後應用轉換:

CGAffineTransform myTransformation = CGAffineTransformMakeScale(((UIPinchGestureRecognizer *)sender).scale, ((UIPinchGestureRecognizer *)sender).scale); 
self.fullScreenImageView.transform = myTransformation; 

一旦捏收到結束狀態,我會淡入黑色並調整框架。我決定不採用這種方法,因爲我認爲只是認識到捏或雙擊是足夠好的。

+0

酷!你是在自問自答。請標記它,這樣其他人將受益.. –

+0

是的,我會的。必須等待兩個小時。 :) –

+0

你先生,是個學者和紳士。精美的作品 – MrTristan

0

您必須將UIImageView嵌入到UIControl中,並將IBAction鏈接到UIControl事件。

0

在圖像視圖上使用UIPinchGestureRecognizer可識別捏合和UIView轉換方法,以將圖像視圖最大化爲全尺寸。

+0

你是什麼意思的UIView過渡方法? –

+0

@Bob:名稱以「transition」開頭的UIView類方法;例如,[transitionWithView:duration:options:animations:completion:](http://developer.apple.com/library/ios/documentation/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/ CLM /的UIView/transitionWithView:持續時間:選擇:動畫:完成:)。 – Jesper

+0

好的。我仍然不太確定我會如何做到這一點。任何例子?因此,如果我在表格視圖中顯示照片的小版本,我是否會創建一個全屏顯示並在兩者之間轉換的新視圖?如果我的桌子坐在分離式視圖中,我的新創建的全屏視圖必須在哪裏存在(超級觀察明智)才能正常工作? –

相關問題