我有一个带有图像图标的视图,我想在点击该图标时弹出该图像。
我认为可以使用UIpopovercontroller
。
我是iPhone开发的新手。希望你的帮助。感谢名单..
答案 0 :(得分: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];
}