UIImageView显示UIPopOver

| 我想启动此事件:
- (IBAction)profilePop:(id)sender
{
    ProfileViewController * profile = [[ProfileViewController alloc] init];
    UIImageView * temp = ((UIImageView *)sender);
    profile.uid =  [[[posts objectAtIndex:((UIImageView *)sender).tag] creator] mid];
    NSLog(@\"profile id %@\", profile.uid);
    UIPopoverController * profilePop  = [[UIPopoverController alloc] initWithContentViewController:profile];
    [profilePop presentPopoverFromRect:CGRectMake(temp.frame.origin.x+temp.frame.size.width, temp.frame.origin.y + temp.frame.size.height/2, profile.view.frame.size.width, profile.view.frame.size.height) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
}
当用户点击UIImageView时。我要做的就是单击UIImageView时显示一个弹出窗口,它显示在UIImageView的右侧。我看到UIImageView没有它的addAction属性,因为它不是UIControl的子类。我做了一些研究,可能不得不改用UIButton。这是真的?有没有一种方法可以使用UIImageView做到这一点,所以我不必再次重写代码?一世     
已邀请:
第一。 您可以触摸任何具有超类
UIView
的对象。 如果您在Apple文档中看到UIImageView。
UIView : UIResponder : NSObject
UIResponder具有获取触摸的功能。因此,在您的视图类中实现以下功能,并检测ѭ3上的触摸。
– touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
– touchesCancelled:withEvent:
第二: 您也可以为
UIImageView
创建
UITapGestureRecognizer
。 查看以下博客教程。 使用UIGestureRecognizers 编辑: 使用以下代码:
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]             initWithTarget:self action:@selector(tapped:)];
[tapRecognizer setNumberOfTapsRequired:1];
[tapRecognizer setDelegate:self];
[MyImageView addGestureRecognizer:tapRecognizer];
如果用户点击一次,则将调用轻按的函数,因此选项卡式的函数应如下所示
 -(void)tapped:(id)sender
     {

       NSLog(@\"See a tap gesture\");

         ProfileViewController * profile = [[ProfileViewController alloc] init];
         UIImageView * temp = [(UIPanGestureRecognizer*)sender view];
        profile.uid =  [[[posts objectAtIndex:((UIImageView *)sender).tag] creator] mid];
        NSLog(@\"profile id %@\", profile.uid);
        UIPopoverController * profilePop  = [[UIPopoverController alloc] initWithContentViewController:profile];
      [profilePop presentPopoverFromRect:CGRectMake(temp.frame.origin.x+temp.frame.size.width, temp.frame.origin.y + temp.frame.size.height/2, profile.view.frame.size.width, profile.view.frame.size.height) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
    }
    
代替使用UIButton并使用class方法向其中添加UIImage怎么样。
- (void)setImage:(UIImage *)image forState:(UIControlState)state 
    
您可以定义类型为custom的UIButton,不给其任何文本或图像,给其清晰的背景,并与图像视图使用相同的框架。然后将您的目标/选择器添加到该按钮,当他们实际上点击一个不可见的按钮时,它将向用户显示他们正在点击图像视图。在IB中设置大约需要3分钟,因此我认为您无需再次重写代码。     
您可以创建一个Tap Gesture识别器,并将其附加到UIImageView。
// By now imageView exists!
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
[imageView addGestureRecognizer:tapGesture];
[tapGesture release];
现在
handleTapGesture
与您的
-profilePop:
非常相似 由于您在谈论弹出式控制器,因此我假设您已经有手势识别器。     

要回复问题请先登录注册