触摸开始驳回视图

发布于 2024-12-12 19:09:03 字数 838 浏览 6 评论 0原文

我有一个带有全屏 UIImageView 的 ViewController。我隐藏了状态栏和导航栏,因此除了点击某处之外无法返回。

所以我想回去只是使用这个 TouchsBegan

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{    
    [self dismissModalViewControllerAnimated:YES];
}

我也尝试使用这种方式

-(void)viewDidLoad 
{
    [super viewDidLoad];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    [self.navigationController setNavigationBarHidden:YES];

    UITapGestureRecognizer *tapRecognizer;
    tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissModalViewControllerAnimated:)];
    [imageFrame addGestureRecognizer:tapRecognizer];

    imageFrame.image = [UIImage imageWithContentsOfFile:image];

    [tapRecognizer release];
}

我被困在那里,用这个全屏图像,我无法回去。 我怎样才能关闭视图控制器?

I have a ViewController with a full screen UIImageView. I've hidden statusBar and NavigationBar, so there is no way to go back but tapping somewhere.

So i was thinking to go back just using this touchesBegan

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{    
    [self dismissModalViewControllerAnimated:YES];
}

I also tried to use this way

-(void)viewDidLoad 
{
    [super viewDidLoad];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    [self.navigationController setNavigationBarHidden:YES];

    UITapGestureRecognizer *tapRecognizer;
    tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissModalViewControllerAnimated:)];
    [imageFrame addGestureRecognizer:tapRecognizer];

    imageFrame.image = [UIImage imageWithContentsOfFile:image];

    [tapRecognizer release];
}

I got stuck there, with this full screen image and i can't go back.
How can I dismiss the viewcontroller?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深爱成瘾 2024-12-19 19:09:03

如果您使用导航栏,我假设您使用了 PushViewController 来启动此视图控制器?在这种情况下,您需要

[self.navigationController popViewControllerAnimated:YES];

关闭控制器。

If you are using a navigation bar I'm assuming that you did a pushViewController to start this view controller? In which case you would want

[self.navigationController popViewControllerAnimated:YES];

to dismiss the controller.

厌味 2024-12-19 19:09:03

当然,您的解决方案假设图像视图实际上是一个模态视图控制器,在某处以 presentModalViewController:animated: 呈现。

我的建议是将 UIButton 放置在图像视图的顶部并且大小相同。将其 Touch Up Inside 连接到您的返回方法,然后将其 alpha 设置为 0 或通过 IB 或属性隐藏它。该按钮不会显示,但仍会接收触摸事件。

Of course your solution assumes that the image view is in fact a modal view controller presented with presentModalViewController:animated: somewhere.

My suggestion would be to have a UIButton placed on top of your image view and sized the same. Hook up its Touch Up Inside to your go-back method and then set its alpha to 0 or Hide it through IB or properties. The button won't be displayed but it'll still receive touch events.

爱你不解释 2024-12-19 19:09:03

您应该在父视图控制器上调用dismissModalViewControllerAnimated:,而不是在您想要隐藏的视图控制器上。

还要确保将 UIImageView 的 userInteractionEnabled 属性设置为 yes,因为与常规 UIView 不同,它默认情况下不响应触摸事件。

You should call dismissModalViewControllerAnimated: on the parent view controller, and not on the one you wanna hide.

Also make sure to set the UIImageView's userInteractionEnabled property to yes, because unlike regular UIView's it doesn't answer touch events by default.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文