1

嗨,我在 UIView 中有一个 UIScrollView。我尝试使用我在网上找到的代码片段,但它们根本没有改变任何东西。此外,它们主要用于在 UIView 中完成的图像或自定义视图,而在我的情况下,我有一组以编程方式创建的 UILabel。我也尝试过更改边界值,它根本没有做任何事情。这基本上是我如何在 viewDidAppear 中确定它的大小:

[scrollView setContentSize:CGSizeMake([screenView getWidth], [screenView getHeight])];


scrollView.showsHorizontalScrollIndicator = true;
scrollView.showsVerticalScrollIndicator = true;

screenView 是一个 UIView 变量。

这是我使用的设置(也在 viewDidAppear 中):

doubleTapRecogniser = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapResponse:)];
    [doubleTapRecogniser addTarget:self action:@selector(doubleTapResponse:)];


    doubleTapRecogniser.delegate = self;

    doubleTapRecogniser.numberOfTapsRequired = 2;

    [self.scrollView addGestureRecognizer:doubleTapRecogniser];

这就是我实现双击方法的方式:

- (void) doubleTapResponse:(UITapGestureRecognizer *)recogniser
{

    CGFloat newZoomScale = self.scrollView.zoomScale / 1.5f;
    newZoomScale = MAX(newZoomScale, self.scrollView.minimumZoomScale);
    [self.scrollView setZoomScale:newZoomScale animated:YES];
}

当我在我的 NSLog 中使用消息时doubleTapResponse,我可以从我的控制台获得响应。然而它什么也没做。可能是什么问题?我使用的是 iOS6.1

4

2 回答 2

0
[doubleTapRecogniser addTarget:scrollView action:@selector(doubleTapResponse:)];

应该

[doubleTapRecogniser addTarget:self action:@selector(doubleTapResponse:)];

因为滚动视图不知道该方法 doubleTapResponse 是什么。目前它正在抛出异常,因为它试图用你的 doubleTapResponse 方法调用 UISCrollView 的目标,你必须添加 self 的目标,并自己实现这个方法。我假设的缩放逻辑在这里。

您还必须在视图控制器(或您正在使用的类)中定义:doubleTapResponse

有关更多信息,请参见: Ray Wenderlich 指南

为了放大,请查看以下文章:问题

于 2013-08-05T04:22:03.663 回答
0

该错误清楚地表明运行时在您正在使用的滚动视图类中搜索了一个名为 doubleTapResponse 的方法。即使将目标更改为 self 不起作用,它的方法定义位置也必须更改滚动视图或视图控制器。

于 2013-08-05T04:28:40.357 回答