【问题标题】:How to dismiss the UIAlertview on the click of UIViewController or on the UIScrollView in objective c如何在单击 UIViewController 或在目标 c 中的 UIScrollView 上关闭 UIAlertview
【发布时间】:2017-03-21 23:34:30
【问题描述】:

我是 iOS 新手,我正面临关闭 UIAlertview 的问题。我在 UIAlertview 中显示图像,并且我正在使用长按手势来调用警报视图。我的代码是这样的

ImageName.userInteractionEnabled=YES;
    UILongPressGestureRecognizer *longpressgestureRecognizer = [[UILongPressGestureRecognizer alloc] init];
    [longpressgestureRecognizer addTarget:self action:@selector(imgLongPressed:)];
    longpressgestureRecognizer.delegate = self;
    [ImageName addGestureRecognizer: longpressgestureRecognizer];

- (void) imgLongPressed:(UILongPressGestureRecognizer*)sender
{
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 282)];
    UIImage *wonImage = ImageName.image;
    imageView.contentMode=UIViewContentModeCenter;
    [imageView setImage:wonImage];
    alertView = [[UIAlertView alloc] initWithTitle:@""
                                                        message:@""
                                                       delegate:self
                                              cancelButtonTitle:nil
                                              otherButtonTitles:@"OK", nil];
    //check if os version is 7 or above
    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
        [alertView setValue:imageView forKey:@"accessoryView"];
    }else{
        [alertView addSubview:imageView];
    }
    [alertView show];
    [self performSelector:@selector(dismiss:) withObject:alertView afterDelay:1.0];
}


-(void)dismiss:(UIAlertView*)alert
{
    [alert dismissWithClickedButtonIndex:-1 animated:YES];
}

这段代码给我这样的图像输出

我需要在触摸 UIViewController 或 UIScrollView 时关闭 UIAlertview。

【问题讨论】:

  • 好吧,UIAlertView 已被弃用 (UIAlertController),你不应该在 iOS7 之后使用它的子视图(这就是为什么你有一个特定的代码)。你确定要保持这个方向吗?并不是说您可能想为您的 UIImageView 添加一个 userInteractionEnabled 为 YES。
  • @Larme 是的,我想保持同一个方向。

标签: ios objective-c xcode uiviewcontroller uiscrollview


【解决方案1】:

UIAlertView 已折旧。通常不建议使用折旧的元素,因为它们可能会导致最新版本的 iOS 出现一些问题。对于给定的功能,我认为最好使用像这样的第三方 AlertViews:https://cocoapods.org/pods/SCLAlertView-Objective-C

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-04
    • 2012-04-04
    • 1970-01-01
    • 2012-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多