【问题标题】:How to make an image go fullscreen in iOS app [duplicate]如何在iOS应用程序中使图像全屏显示[重复]
【发布时间】:2013-06-05 10:21:41
【问题描述】:

我是 xcode 和 Objective c 的新手,我想知道如何使用轻按手势使图像在触摸时全屏显示... 谁能帮帮我?

这是我尝试过的代码:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tap.numberOfTapsRequired = 1;
tap.cancelsTouchesInView = NO;
imageView.userInteractionEnabled = YES;
[imageView addGestureRecognizer:tap];
}

-(void)handleTap{
imageView.frame=CGRectMake(0,0,320,480);

}

【问题讨论】:

标签: ios objective-c image fullscreen


【解决方案1】:

您可以更改图像视图的帧大小,然后它会自动进入全屏模式。

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture)];
tapGesture.numberOfTapsRequired=1;
[imageView setUserInteractionEnabled:YES];
[imageView addGestureRecognizer:tapGesture];

-(void)handleTapGesture{
    imageView.frame=CGRectMake(0,0,320,480);

}

【讨论】:

  • 我刚收到这个错误信息:@autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
  • 你把这段代码保存在哪里?
  • 我把它放在 ViewDidLoad [super viewDidLoad] 下
  • 在您尝试过的问题中发布您的代码。
  • 把@selector(handleTap:)中的冒号(:)去掉试试看。
【解决方案2】:

这个

// Detecting touches on your UIImageView
UITapGestureRecognizer *myImageViewTapped = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                               action:@selector(changeFrameOfMyImage)];

myImageViewTapped.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:myImageViewTapped];

//...
//...

-(void)changeFrameOfMyImage {
    myImageView.frame = self.view.frame;
}

可能会成功!

【讨论】:

    【解决方案3】:
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
        tapGesture.numberOfTapsRequired = 1;
        tapGesture.cancelsTouchesInView = NO;
        imageView.userInteractionEnabled = YES;
        [imageView addGestureRecognizer:tapGesture];
    
        -(void)handleTemplateTap:(UIGestureRecognizer *)sender
        {
             imageview.frame=CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);
        }
    

    【讨论】:

    • 谢谢!我要把什么放在哪里?我要在 .h 文件中写什么?
    猜你喜欢
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    • 2018-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-28
    相关资源
    最近更新 更多