无法找到“滚动视图”属性以了解滚动视图滚动的像素数

时间:2015-01-02 15:11:22

标签: ios objective-c uiscrollview uiscrollviewdelegate

我有一个带有标签的滚动视图,我想在有人滚动标签X px' s到右边并释放他的手指以动画删除这个标签。

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

- (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 !!

2 个答案:

答案 0 :(得分:1)

检查UIScrollView的contentOffset属性:

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

答案 1 :(得分:0)

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

- (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];
            }];
        }];




    }
}