在滚动视图中使用 imgview 返回视图时的 EXC_BREAKPOINT

Posted

技术标签:

【中文标题】在滚动视图中使用 imgview 返回视图时的 EXC_BREAKPOINT【英文标题】:EXC_BREAKPOINT when going back to view with imgview in scrollview 【发布时间】:2013-03-28 16:42:43 【问题描述】:

我在这样的滚动视图中从另一个视图调用带有 imgView 的视图

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    ImageViewController *view = [[self.menus objectAtIndex:[indexPath row]] objectForKey:@"VIEW"];
    view.imgPath = [[self.menus objectAtIndex:[indexPath row]] objectForKey:@"PATH"];
    [self presentViewController:view animated:YES completion:nil];

然后我像这样在新视图中显示图像

-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

    return self.imgView;


- (void)viewWillAppear:(BOOL)animated 
    [super viewWillAppear:animated];
    NSString *path = [[NSBundle mainBundle] pathForResource:self.imgPath ofType:@"png"];
    UIImage *image = [[UIImage alloc] initWithContentsOfFile:path];
    self.imgView = [[UIImageView alloc] initWithImage:image];
    self.imgView.frame = (CGRect).origin=CGPointMake(0.0f, 0.0f), .size=image.size;
    [self.scrollView addSubview:self.imgView];
    self.scrollView.contentSize = image.size;
    CGRect scrollViewFrame = self.scrollView.frame;
    CGFloat scaleWidth = scrollViewFrame.size.width / self.scrollView.contentSize.width;
    CGFloat scaleHeight = scrollViewFrame.size.height / self.scrollView.contentSize.height;
    CGFloat minScale = MIN(scaleWidth, scaleHeight);
    self.scrollView.minimumZoomScale = minScale;
    self.scrollView.maximumZoomScale = 1.0f;
    self.scrollView.zoomScale = minScale;

    [self centerScrollViewContents];


- (void)viewDidLoad

    [super viewDidLoad];

    UITapGestureRecognizer *doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrollViewDoubleTapped:)];
    doubleTapRecognizer.numberOfTapsRequired = 2;
    doubleTapRecognizer.numberOfTouchesRequired = 1;
    [self.scrollView addGestureRecognizer:doubleTapRecognizer];

    UITapGestureRecognizer *twoFingerTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrollViewTwoFingerTapped:)];
    twoFingerTapRecognizer.numberOfTapsRequired = 1;
    twoFingerTapRecognizer.numberOfTouchesRequired = 2;
    [self.scrollView addGestureRecognizer:twoFingerTapRecognizer];


- (void)centerScrollViewContents 
    CGSize boundsSize = self.scrollView.bounds.size;
    CGRect contentsFrame = self.imgView.frame;

    if (contentsFrame.size.width < boundsSize.width) 
        contentsFrame.origin.x = (boundsSize.width - contentsFrame.size.width) / 2.0f;
     else 
        contentsFrame.origin.x = 0.0f;
    

    if (contentsFrame.size.height < boundsSize.height) 
        contentsFrame.origin.y = (boundsSize.height - contentsFrame.size.height) / 2.0f;
     else 
        contentsFrame.origin.y = 0.0f;
    

    self.imgView.frame = contentsFrame;

这一切都没有问题,我可以像这样关闭视图

- (IBAction)BackBtnPress:(id)sender 
    [self dismissViewControllerAnimated:YES completion:nil];

但是,当我想从 didSelectRowAtIndexPath 再次返回图像视图时,应用程序崩溃并且我在

处得到 EXC_BREAKPOINT
0x18e2756:  calll  0x1a37a00                 ; symbol stub for: getpid

我尝试过调试,它通过 viewWillAppear 几乎没有问题,然后崩溃

对可能出现的问题有什么想法吗?

谢谢!

编辑

启用僵尸没有帮助,禁用弧线没有任何改变。

【问题讨论】:

【参考方案1】:

我通过在选择行时创建新的 imageview 来修复它,而不是在加载带有 tableview 的第一个视图时,所以我的 didselectrowatindexpath 看起来像这样

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    ImageViewController *view = [ImageViewController alloc];
    view.imgPath = [[self.menus objectAtIndex:[indexPath row]] objectForKey:@"PATH"];
    [self presentViewController:view animated:YES completion:nil];

【讨论】:

以上是关于在滚动视图中使用 imgview 返回视图时的 EXC_BREAKPOINT的主要内容,如果未能解决你的问题,请参考以下文章

触摸滚动视图时的 UIImageView 旋转 - iOS

子类化 UIScrollView 时的奇怪行为

滚动时的 iOS TableView 索引值

滚动水平集合视图时的随机行为

中心控制器具有滚动视图时的 MMDrawerController 平移手势行为

Web视图添加hardwareAccelerated时的滚动问题为false