如何将操作发送到 UIImage 子视图(从 UIAlertView 委托)
本质上我有一个弹出的 UIAlertView
。当用户选择一个按钮时,它会调用自身,并根据按钮索引调出一个 UIImageView 子视图。我的问题是,由于 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];
}
}
Essentially I have a UIAlertView
that pops up. When a user selects a button it calls itself, and based on the button index it brings up a UIImageView
subview. My question is, because the UIImageView
takes up a good portion of the screen it lays on top of the UIAlertView
, so the cancel button is unseen. I was wondering if I could create actions on the UIImageView so that if it is clicked or touched up inside, the UIAlertView
/UIImageView
would resign and disappear?
Someone please help, I've been tooling around this for hours.
Here is the code from the button being clicked, and the button index.
- (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];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MyImageView.h
MyImageView.m
MyViewController.h
MyViewController.m
然后在创建 imageView 时
MyImageView.h
MyImageView.m
MyViewController.h
MyViewController.m
then while create imageView