gpt4 book ai didi

ios - UIPopOverControl 和 UIImageView

转载 作者:行者123 更新时间:2023-11-29 04:05:58 27 4
gpt4 key购买 nike

我创建了一个 UIButtonUIImageView,其中按钮框架设置为与图像框架大小相同。我愿意做的是,一旦我触摸图像,它应该PopOver。按钮设置为 Action 。问题是,一旦我触摸它,它就只显示图像,而不是弹出。

我的代码有什么问题吗?

- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(10, 10,100, 100)];
imageView.image=[UIImage imageNamed:@"abc.jpg"];
[self.view addSubview:imageView];
imageView.userInteractionEnabled = YES;
UIButton *imageButton = [[UIButton alloc]init];
[imageButton setFrame:CGRectMake(0, 0, 100, 100)];
[imageButton addTarget:self action:@selector(imageTapped:) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:imageButton];
[imageButton release];
[imageView release];
}


-(void)imageTapped:(UIButton*)in_sender {
UIViewController *popoverContent = [[UIViewController alloc] init];
CGRect theScreenFrame = [[UIScreen mainScreen] bounds];
popoverContent.view.frame = CGRectMake(theScreenFrame.origin.x, theScreenFrame.origin.y,100, 100);
popoverContent.view.backgroundColor = [UIColor whiteColor];
popoverContent.contentSizeForViewInPopover = CGSizeMake(300, 300);
[popoverContent.view addSubview:imageButton];

if(m_DetailPopover) {
[m_DetailPopover release];
m_DetailPopover = nil;
}
UIPopoverController m_DetailPopover = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[popoverContent release];

[m_DetailPopover presentPopoverFromRect:imageButton.frame inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

最佳答案

问题可能是代码中的拼写错误:

UIPopoverController *m_DetailPopover = [[UIPopoverController alloc] initWithContentViewController:popoverContent];

另请注意,您不能在 imageTapped 中引用 imageButton,因为你在 viewDidLoad 中释放它。

关于ios - UIPopOverControl 和 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15223200/

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