Search code examples
iosobjective-cuipopovercontroller

Popup the image icon which resides in my UIView-Objective C


I do have a view with an image icon, I want to popup that image when I clicked on that icon. I think it is possible with UIpopovercontroller. I am a new guy to iPhone development. hope your help. Thanx..


Solution

  • you can do this like this, create outlet of your icon in .h file and make it user interaction property selected

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

    and in .m file.

        - (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];
    }