Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 找不到滚动视图属性,无法知道滚动视图滚动了多少像素_Ios_Objective C_Uiscrollview_Uiscrollviewdelegate - Fatal编程技术网

Ios 找不到滚动视图属性,无法知道滚动视图滚动了多少像素

Ios 找不到滚动视图属性,无法知道滚动视图滚动了多少像素,ios,objective-c,uiscrollview,uiscrollviewdelegate,Ios,Objective C,Uiscrollview,Uiscrollviewdelegate,我有一个滚动视图,其中有一个标签,我想在有人将标签X px向右滚动并释放他的手指后,用动画删除这个标签 因此,我创建了一个委托连接,并添加了滚动视图委托方法: - (void)scrollViewDidScroll:(UIScrollView *)scrollView { NSLog(@"scroll view did scroll"); } 在这个方法中,我想说: if myScrollView.someProperty moved X px's to the right and

我有一个滚动视图,其中有一个标签,我想在有人将标签X px向右滚动并释放他的手指后,用动画删除这个标签

因此,我创建了一个委托连接,并添加了滚动视图委托方法:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

    NSLog(@"scroll view did scroll");
}
在这个方法中,我想说:

if myScrollView.someProperty moved X px's to the right and the user pulled his finger 

delete this label sliding with animation to the right
有人能帮忙吗/


tnx在前面

检查UIScrollView的contentOffset属性:

contentOffset - The point at which the origin of the content view is offset 
from the origin of the scroll view.

您可以使用UISweepGestureRecognitor执行此操作,并定义要向右拖动标签的像素数。您可以尝试以下代码

- (void)viewDidLoad {
    [super viewDidLoad];
    mylabel.userInteractionEnabled=YES;
    [mylabel sizeToFit];
    [mylabel addGestureRecognizer:[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeLabel:)]];

}

- (void)didSwipeLabel:(UISwipeGestureRecognizer*)swipe
{
    NSLog(@"swipe");

    swipe.direction = UISwipeGestureRecognizerDirectionRight;
    if (swipe.direction == UISwipeGestureRecognizerDirectionRight) {
        [UIView animateWithDuration:0.5 animations:^{
            // swipe the label 50px right
           mylabel.transform = CGAffineTransformMakeTranslation(50.0, 0.0);
        } completion:^(BOOL finished) {
            // when animation
            [UIView animateWithDuration:0.5 animations:^{
                 NSLog(@"label should be removed");
                [mylabel removeFromSuperview];
            }];
        }];




    }
}

也许是斯克罗尔