【问题标题】:How to convert type of recogniser's view?如何转换识别器视图的类型?
【发布时间】:2023-03-21 18:38:02
【问题描述】:
-(void)tapDetected:(UIGestureRecognizer*)recognizer{
(UIImageView)(recognizer.view).tag)
    ;} 

我想将识别器视图的类型转换为图像视图,以便我可以使用图像标签作为参考。我该怎么做?

【问题讨论】:

    标签: iphone xcode uiview uiimageview uigesturerecognizer


    【解决方案1】:

    tag 属性在 UIView 中声明,而不是在 UIImageView 中声明。不需要演员表。

    NSInteger myTag = recognizer.view.tag;
    

    出于说明目的,如果您愿意,这就是您将视图投射到UIImageView 的方式,例如,访问其image 属性:

    UIImage *img = ((UIImageView *)recognizer.view).image;
    

    为了方便使用,可以使用局部变量,让后续的访问更干净:

    UIImageView *imageView = (UIImageView *)recognizer.view;
    UIImage *img = imageView.image;
    

    【讨论】:

    • 我已经定义了图像视图的标签。现在我要求当我点击图像时,然后在控制台上打印该图像的标签。
    • @ram 你在纠结什么?
    • 我在带有滚动视图的图像视图中有图像数组。点击图片时,我想从网络服务上传相同的大图。
    • @ram 这是一个比你的问题更广泛的话题。如果您遇到新的困难,我建议您提出一个新问题。
    猜你喜欢
    • 2020-05-26
    • 2020-06-19
    • 2022-01-18
    • 2011-06-28
    • 2021-04-19
    • 2021-03-07
    • 1970-01-01
    • 1970-01-01
    • 2015-03-21
    相关资源
    最近更新 更多