iPhone SDK - 使用触摸删除图像

标签 iphone ios xcode image touches

如何在 iphone sdk 中使用触摸删除图像?我正在制作一个带有图像的游戏,所以我想知道是否有一种方法可以在您触摸图像时将其从 View 中删除。

最佳答案

是的。您可以将 UITapGestureRecognizer 添加到 ImageView ,在识别器操作中,您可以使用 recognizer.view 属性获取 ImageView 。您可以使用 [image removeFromSuperview] 方法从其 super View 中删除/移除它。

UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onImageTapped:)];
[imageView addGestureRecognizer:tgr];
[tgr release];

onImageTapped: 方法如下所示,

- (void)onImageTapped:(UITapGestureRecognizer*)recognizer {

    UIImageView *imgView = (UIImageView*) recognizer.view;
    [imgView removeFromSuperview];
}

关于iPhone SDK - 使用触摸删除图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6765029/

相关文章:

ios - iphone ios 7 主屏幕掩码未正确应用于我的图标

ios - iPhone 何时会在状态栏中显示固定位置图标?

ios - 避免类对象数组中的重复 Swift 3

iOS 应用内购买和检测自动更新订阅

ios - delaysContentTouches = false 不在 UITableView Swift 中工作?

iphone - 防止 IOS 应用程序在语言更改后重新启动

iphone - JSON响应编码问题

xcode - 从 iPhone 应用程序在 Facebook 应用程序中打开 Facebook 帖子

iphone - "Run destination iOS Device is not valid"运行 3.1.3 和 XCode 4 的 iPod Touch

iphone - "Program received signal: EXC_BAD_ACCESS"- 如何识别触发的行?