UIView没有使用UIView动画正确动画

时间:2016-10-03 17:25:17

标签: ios objective-c uiview

我正在研究UIView Animation。我向上滚动时向上移动视图,向下滚动时向下移动。

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGPoint scrollVelocity = [_collectionViewLeaderboard.panGestureRecognizer velocityInView:_collectionViewLeaderboard.superview];
if (scrollVelocity.y > 0.0f){
    NSLog(@"going down");
    [UIView animateWithDuration:0.3f
                              animations:^ {

                                  _headerview.frame = CGRectMake(0, 0, _headerview.frame.size.width, _headerview.frame.size.height);

                                  _headerviewSecond.frame = CGRectMake(0, _headerview.frame.size.height, _headerviewSecond.frame.size.width, _headerviewSecond.frame.size.height);

                                  self.collectionViewLeaderboard.frame = CGRectMake(self.view.frame.origin.x, _headerviewSecond.frame.size.height+_headerview.frame.size.height, self.view.frame.size.width, self.view.frame.size.height);

                                  frameconditon = _headerview.frame;
                                  _viewOptions.frame = CGRectMake(_viewOptions.frame.origin.x,_headerview.frame.size.height+_headerviewSecond.frame.size.height+30, _viewOptions.frame.size.width, _viewOptions.frame.size.height);

                                      } completion:^ (BOOL completed) {

                              }];

}
else if (scrollVelocity.y < 0.0f){
    NSLog(@"going up");

               [UIView animateWithDuration:5.3 animations:^{


                   _headerview.frame = CGRectMake(_headerview.frame.origin.x, -(_headerview.frame.size.height), _headerview.frame.size.width, _headerview.frame.size.height);

                   _headerviewSecond.frame = CGRectMake(0, (_headerview.frame.size.height)-40, _headerviewSecond.frame.size.width, _headerviewSecond.frame.size.height);

                   self.collectionViewLeaderboard.frame = CGRectMake(self.view.frame.origin.x, _headerviewSecond.frame.size.height, self.view.frame.size.width, self.view.frame.size.height);
                    frameconditon = _headerviewSecond.frame;

                   _viewOptions.frame = CGRectMake(_viewOptions.frame.origin.x,_headerviewSecond.frame.size.height+20, _viewOptions.frame.size.width, _viewOptions.frame.size.height);

        } completion:^(BOOL finished) {

        }];

    }
}

1 个答案:

答案 0 :(得分:0)

如果您想要上下移动视图,我认为这很简单。 因为如果在滚动视图中添加视图,则可以使用滚动自动上下查看视图。你只需要设置&#34; contentSize&#34; scrollView的属性。

如果不是这样的话,你试图获得UICollectionView的panGesture然后你就无法进入&#34; scrollViewDidScroll&#34;方法

以下是UIPanGestureRecognizer与UICollectionView的有用教程。希望如此有用。

https://uncorkedstudios.com/blog/using-uigesturerecognizers-with-uicollectionviews