UIScrollView子视图与UITapGestureRecognizer一起使用时释放(删除)内存

时间:2013-11-01 20:35:31

标签: ios uiscrollview uiimageview uitapgesturerecognizer subviews

示例非常简单,一大堆UIImageView被添加为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];
}

点击UIImageView后,会将其发送到wideDisplay:方法以便广泛展示:

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

}

将imageView添加到模态视图后,将从scrollview子视图中删除此UIImageView。 imageView是一个强大的属性,但尽管如此,在添加到自定义模态视图后,它似乎失去了参考,如何防止它在选择后从scrollview中删除?

1 个答案:

答案 0 :(得分:0)

每次致电self.imageView时,您是不是在处理和创建-wideDisplay: