无法找到滚动视图属性以了解滚动视图滚动了多少像素
Cant find the Scroll View property to know how many pixels the scroll view did scroll
我有一个带有标签的滚动视图,我希望有人将标签 X 像素向右滚动并松开他的手指以删除带有动画的标签。
所以我创建了一个委托连接并添加了滚动视图委托方法:
- (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.
您可以使用 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];
}];
}];
}
}
我有一个带有标签的滚动视图,我希望有人将标签 X 像素向右滚动并松开他的手指以删除带有动画的标签。
所以我创建了一个委托连接并添加了滚动视图委托方法:
- (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.
您可以使用 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];
}];
}];
}
}