像Reeder应用程序一样捏全屏拍照

时间:2011-08-11 07:22:37

标签: iphone objective-c ipad

尝试提出一种方法来完成reeder应用程序创建者在他的iphone / ipad应用程序中执行完全相同的操作,并将照片缩放到全屏幕。

我在表格单元格中有一个uiimageview,我希望在捏开时转换到全屏视图,或者可以双击。想要使用类似的动画。

任何提示都将不胜感激!

3 个答案:

答案 0 :(得分:13)

好的,我设法把它放在一起。不确定如何使用转换方法,但我需要在同一位置复制视图然后将其炸毁。

http://screencast.com/t/MLTuGkIYh

因此,在包含大图像的单元格中,我连接了捏合和敲击手势识别器。

    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;
                     }];
}

如果你想让图片在缩放时实际调整大小,我建议你在捏合开始时立即添加重复的视图(只要缩放&gt; 1)然后应用转换:

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

一旦捏合达到最终状态,我就会淡入黑色并调整框架。我决定不采用这种方法,因为我认为只是认识到捏或双击是足够好的。

答案 1 :(得分:0)

您必须在UIControl中嵌入UIImageView并将IBAction链接到UIControl事件。

答案 2 :(得分:0)

使用图片视图上的UIPinchGestureRecognizer识别夹点和UIView过渡方法,将图像视图吹到最大尺寸。