简体   繁体   中英

UIScrollView subview is memory released (removed) when it's used in conjunction with UITapGestureRecognizer

The example is very simple, a bunch of UIImageView s are added as subviews to a UIScrollView :

for(NSDictionary *dict in info) {
    UIImageView *imageview = [[UIImageView alloc] initWithImage:image];
    imageview.frame = CGRectMake(x, 0, 91, 91);

    [self.scrollView addSubview:imageview];
        x+=95;
        [self.scrollView setContentSize:CGSizeMake(x, 91.0)];
        //define gestures
        //single tap for wide display
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(wideDisplay:)];
        imageview.userInteractionEnabled = YES;
        [imageview addGestureRecognizer:singleTap];
}

after a single tap on a UIImageView , it's sent to the wideDisplay: method to get displayed widely:

-(void)wideDisplay:(UITapGestureRecognizer*)gesture{

    UAModalPanel *wideScreen = [[UAModalPanel alloc] initWithFrame:self.view.bounds];
    wideScreen.padding = UIEdgeInsetsMake(20.0, 20.0, 20.0, 20.0);

    self.imageView = [[UIImageView alloc]init];
    self.imageView = (UIImageView*)gesture.view;
    self.imageView.frame = CGRectMake(20, 20, 790, 500);

    [wideScreen.contentView addSubview:self.imageView];
    [self.view addSubview:wideScreen];    

}

after adding the imageView to the modal view, this UIImageView is removed from the scrollview subviews. imageView is a strong property, but despite that, seems that it's loosing reference after being added to custom modal view, how to prevent it from being removed from the scrollview after selecting it?

您不是在每次调用-wideDisplay:时都处理并创建self.imageView吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM