ios - 点击 imageView 查看全屏图像

标签 ios objective-c image uiimageview

我的详细 View 中有一个 uiimageview,我想制作它以便当我点击图像时,它会全屏打开图像。但是,我下面的代码似乎不起作用。知道我做错了什么吗?

FullViewController.h

@interface FullArticleViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIGestureRecognizerDelegate>


    {
        IBOutlet UITapGestureRecognizer *tap;
        IBOutlet UIScrollView *scroller;
        IBOutlet UILabel *firstnameLabel;
        IBOutlet UILabel *bodyLabel;
        IBOutlet UILabel *descriptionLabel;


        BOOL isFullScreen;
        CGRect prevFrame;        
    }

FullViewController.m

   - (void)viewDidLoad
    {

        [super viewDidLoad];
        // Do any additional setup after loading the view from its nib.

           if ([[articleDetail objectForKey:@"ytID"] isEqualToString:@"none"]) {

           featureImage.userInteractionEnabled = YES;

           NSString *imageUrl = [NSString stringWithFormat:@"image/%@",cellImageLink];

           [self.featureImage sd_setImageWithURL:[NSURL URLWithString:imageUrl]];

           [scroller setScrollEnabled:YES];

           featureImage.userInteractionEnabled = YES;

           [scroller bringSubviewToFront:featureImage];

        UITapGestureRecognizer *tapgesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imgToFullScreen)];
        [tapgesture setNumberOfTapsRequired:1];

        [featureImage addGestureRecognizer:tap];

    }

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;
    {
        BOOL shouldReceiveTouch = YES;

        if (gestureRecognizer == tap) {
            shouldReceiveTouch = (touch.view == featureImage);
        }
        return shouldReceiveTouch;
    }

    -(void)imgToFullScreen{
        if (!isFullScreen) {
            [UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
                //save previous frame
                prevFrame = featureImage.frame;
                [featureImage setFrame:[[UIScreen mainScreen] bounds]];
            }completion:^(BOOL finished){
                isFullScreen = true;
            }];
            return;
        } else {
            [UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
                [featureImage setFrame:prevFrame];
            }completion:^(BOOL finished){
                isFullScreen = false;
            }];
            return;
        }
    }

编辑:查看上面更新的代码和下面的层次结构

enter image description here

最佳答案

在你的 viewDidLoad: 方法中试试这个:

[featureImage setUserInteractionEnables:YES];

UITapGestureRecognizer *tapgesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imgToFullScreen)];
[tapgesture setNumberOfTapsRequired:1];
[featureImage addGestureRecognizer:tapgesture];

关于ios - 点击 imageView 查看全屏图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25824904/

相关文章:

ios - 自定义标注 View 按钮到 map

ios - 在 Objective C 中使用 static init 有什么好处?

objective-c - Cocoa 中的可拖动对象

ios - UIAlertController 无法满足约束

android - 十亿像素图像 Android 应用

iphone - 如何知道 cocoahttpserver 何时启动

ios - UITableViewWrapperView 在 tvOS 上具有 super View 的前导和尾随边距

iphone - 从 iOS 应用读取 SD 卡文件

android 图像被文本包裹

ios - 从 url 获取的图像以及如何在 iPhone 中减小图像大小