我创建了一个按钮框架设置为与图像框架大小相同的位置UIButton
。 UIImageView
我愿意做的是一旦我触摸到它应该做的图像PopOver
。按钮设置了动作。问题是,一旦我触摸它,它就只显示图像,而不是弹出。
我的代码有什么问题?
- (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];
}