1

我确实有一个带有图像图标的视图,我想在单击该图标时弹出该图像。我认为这是可能的UIpopovercontroller。我是 iPhone 开发的新手。希望你的帮助。谢谢..

4

1 回答 1

1

你可以这样做,在 .h 文件中创建你的图标的出口并选择用户交互属性

{
    UIImageView *imgView;
    UIImageView *closeimgView;
}
    @property (strong, nonatomic) IBOutlet UIImageView *iconIv;

并在 .m 文件中。

    - (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UITapGestureRecognizer* ivGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ivTapped:)];

    [imageIv addGestureRecognizer:ivGesture];
}
- (void)ivTapped:(id)sender
{
    imgView = [[UIImageView alloc] initWithFrame:CGRectMake(35, 50, 250, 350)]; //create appropriate frame
    imgView.image = [UIImage imageNamed:@"iPhone.jpg"];
    imgView.contentMode = UIViewContentModeCenter;

    [self.view addSubview:imgView];

    closeimgView = [[UIImageView alloc] initWithFrame:CGRectMake(275, 45, 25, 25)]; //create appropriate frame
    closeimgView.image = [UIImage imageNamed:@"close_btn.png"];
    closeimgView.userInteractionEnabled =YES;
    closeimgView.contentMode = UIViewContentModeCenter;
    [self.view addSubview:closeimgView];

    UITapGestureRecognizer* closeivGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeivTapped:)];

    [closeimgView addGestureRecognizer:closeivGesture];


}

- (void)closeivTapped:(id)sender
{
    [imgView removeFromSuperview];
     [closeimgView removeFromSuperview];
}
于 2013-02-16T08:17:32.933 回答