0

別のビューからこのようにスクロールビュー内に 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を通過し、クラッシュします

問題が何であるかについてのアイデアはありますか?

ありがとう!

編集

ゾンビを有効にしても役に立たず、アークを無効にしても何も変わりません。

4

1 に答える 1