【问题标题】:Cannot Drag UIImageView upto the end of the UIScrollview?无法将 UIImageView 拖到 UIScrollview 的末尾?
【发布时间】:2016-07-25 12:41:07
【问题描述】:

我有一个横向内容较大的 UIScrollview。现在我想将 UIImageView 拖到 UIScrollView 的末尾。为此,我正在使用以下代码。

- (void) setUpLeftGesture{

    _leftControlImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, 80, 25)];
    [_leftControlImageView setBackgroundColor:[UIColor yellowColor]];
    [_leftControlImageView setImage:[UIImage imageNamed:@"marker_left_normal"]];
    //add gesture events
    UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftSelector:)];
    [_leftControlImageView addGestureRecognizer:panGestureRecognizer];
    [_leftControlImageView setUserInteractionEnabled:YES];
    [scrollView addSubview:_leftControlImageView];

}

-(void)handleLeftSelector:(UIPanGestureRecognizer *)panGestureRecognizer{

    CGPoint point = [panGestureRecognizer locationInView:self];
    _leftControlImageView.center = point;
}

当我执行上述代码时,我可以拖动 _leftControlImageView(我的 UIImageView)在屏幕尺寸内正常移动。

如果我尝试拖动到 UIScrollView 的末尾,则 UIImageView 不会拖动。我再次回到之前的位置。我不知道为什么会这样。

提前致谢。任何人都可以提供任何建议将视图拖动到 UIScrollview 的末尾。

【问题讨论】:

    标签: ios objective-c iphone cocoa-touch uiscrollview


    【解决方案1】:

    在内容视图中添加图像视图,而不是在滚动视图中。

    【讨论】:

      【解决方案2】:

      如果您想将视图拖到 UIScrollView 的末尾。请确保您的视图 (CustomView) 是否扩展到 UIScrollView。我认为 UIPanGestureRecognizer 将允许我们在它的超类中执行拖放操作。

      所以将你的超类从 UIView 更改为 UIScrollView,就像这样。

      @interface CustomView : UIView
      

      @interface CustomView : UIScrollView
      

      通过这样做,您可以将 UIView 拖到 UIScrollView 的末尾。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-23
        • 1970-01-01
        • 2015-06-29
        • 1970-01-01
        相关资源
        最近更新 更多