找不到滚动视图属性以了解滚动视图滚动了多少像素
Posted
技术标签:
【中文标题】找不到滚动视图属性以了解滚动视图滚动了多少像素【英文标题】:Cant find the Scroll View property to know how many pixels the scroll view did scroll 【发布时间】:2015-01-02 15:11:21 【问题描述】:我有一个带有标签的滚动视图,我想在某人向右滚动标签 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 领先!!
【问题讨论】:
可能是 scool.contentOffset 【参考方案1】:检查 UIScrollView 的 contentOffset 属性:
contentOffset - The point at which the origin of the content view is offset
from the origin of the scroll view.
【讨论】:
【参考方案2】:您可以使用 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];
];
];
【讨论】:
以上是关于找不到滚动视图属性以了解滚动视图滚动了多少像素的主要内容,如果未能解决你的问题,请参考以下文章
水平 UIScrollView 内部有垂直 UIScrollViews - 滚动外部水平视图时如何防止滚动内部滚动视图?