获取动画scrollview的当前位置 [英] Get current position of animated scrollview

查看:159
本文介绍了获取动画scrollview的当前位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了以下问题。



我子类化了一个uiscrollview,其中contentOffset是这个代码的动画:

  [UIView animateWithDuration:1.0 
delay:1.0
options:options
animations:^ {
self.contentOffset = CGPointMake .size.width,0);

}
完成:^(BOOL completed){
// some other stuff
}];

现在,当用户willBeginDraggingscrollview时,我想停止当前动画并设置scrollview.contentoffset到它在uianimation中的当前位置。例如,用户进入屏幕,1秒钟后滚动视图开始滚动,如果用户2秒后触摸滚动并拖动它,scrollview.contentoffset应该具有当前动画位置的确切位置。



如果我获得了willbegindrag中的内容偏移值方法,它已经是动画的最后一个值,因为uianimation将值设置为结束状态,然后生成动画。



如何获取内容的当前位置偏移正在运行的动画?

  NSLog(@pos of content x%f,y%f,[ layer presentationLayer] frame] .origin.x,[[self.layer presentationLayer] frame] .origin.y); 

我读了关于表示层,但是视图本身没有动画,我需要scrollview .contentoffset。



mhh,任何想法? thx



ALREADY SOLVED:



self.layer演示层完全正确。



但是我不得不使用边界而不是框架....



我知道它:P



所以正确的代码是:

  CGPoint pos = [[self.layer presentationLayer] bounds] .origin; 

可在动画时获取动画scrollview的当前位置。



<$ p $

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

NSLog(@%f,scrollView.contentOffset.x);

}


i got the following problem.

i subclassed a uiscrollview which contentOffset is animated by this code:

[UIView animateWithDuration:1.0 
                      delay:1.0
                    options:options
                 animations:^{
                     self.contentOffset = CGPointMake(label.frame.size.width, 0);

                 }
                 completion:^(BOOL completed) {
                     //some other stuff
                 }];

Now, when the user "willBeginDragging" the scrollview, i want to stop the current animation and set the scrollview.contentoffset to the current position it has in the uianimation.

for example, the user gets into the screen, after 1 second the scroll view starts scrolling, if the user touches the scroll after 2 seconds and drag it, the scrollview.contentoffset should have the exact position of the current animation position.

if i get the content offset value in the willbegindrag method, it already as the last value of the animation, as uianimation sets the values to the end state and then animate.

how do i get the current position of the content offset from the running animation?

NSLog(@"pos of content x %f, y %f", [[self.layer presentationLayer] frame].origin.x, [[self.layer presentationLayer] frame].origin.y);

i`ve read about the presentation layer, but the view itself is not animated, i need the scrollview.contentoffset.

mhh, any ideas? thx

ALREADY SOLVED:

The self.layer presentationLayer is absolutely correct.

But i had to use the bounds and not the frame....

Sorry, now you and i know it :P

So the correct code is:

CGPoint pos = [[self.layer presentationLayer] bounds].origin;

to get the current position of an animated scrollview while animating.

解决方案

You can get the content offset while the ScrollView is scrolling using the following code...

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

 NSLog(@"%f", scrollView.contentOffset.x);

}

这篇关于获取动画scrollview的当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆