gpt4 book ai didi

ios - 如何将操作发送到从 UIAlertView 委托(delegate)的 UIImage subview

转载 作者:行者123 更新时间:2023-11-29 13:45:31 25 4
gpt4 key购买 nike

基本上我有一个弹出的UIAlertView。当用户选择一个按钮时,它会调用自己,并根据按钮索引调出一个 UIImageView subview 。我的问题是,因为 UIImageView 占据了屏幕的很大一部分,它位于 UIAlertView 之上,所以看不到取消按钮。我想知道我是否可以在 UIImageView 上创建操作,以便如果在内部单击或触摸它,UIAlertView/UIImageView 会退出并消失?

有人请帮忙,我已经解决这个问题几个小时了。

这是来自被点击按钮的代码,以及按钮索引。

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex     {
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0)
{
// exit(0);
}
else
{
UIAlertView *successAlert = [[UIAlertView alloc] initWithTitle:@"molecule" message:molURL delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 280, 260)];


NSString *MyURL = molURL;

NSString *apURL = [NSString stringWithFormat:@"%@",MyURL];


NSURL * imageURL = [NSURL URLWithString:apURL];
NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage * image1 = [UIImage imageWithData:imageData];


//UIImage *bkgImg = [[UIImage alloc] initWithContentsOfFile:path];
[imageView setImage:image1];


[successAlert addSubview:imageView];

[successAlert show];
}
}

最佳答案

MyImageView.h

#import <UIKit/UIKit.h>

@interface MyImageView : UIImageView {



}

@end

MyImageView.m

#import "MyImageView.h"


@implementation MyImageView


- (id)initWithFrame:(CGRect)frame {

self = [super initWithFrame:frame];
if (self) {

self.userInteractionEnabled=YES;

}
return self;
}


-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

[UIView animateWithDuration:2.0f animations:^(void) {


self.alpha=0.0f;

super.hidden =YES;

UIAlertView *alert=(UIAlertView*)self.superview;


alert.alpha=0.0f;

[alert dismissWithClickedButtonIndex:0 animated:YES];

//or

//[alert removeFromSuperview];

}];




}


- (void)dealloc {
[super dealloc];
}


@end

MyViewController.h

    @class MyImageView;

MyViewController.m

    #import "MyImageView.h"

然后在创建imageView的同时

    MyImageView *specialImageView =[[MyImageView alloc]initWithFrame:CGRectMake(0, 0, 280, 260)];

关于ios - 如何将操作发送到从 UIAlertView 委托(delegate)的 UIImage subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7594168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com