2016-10-03 9 views
-1

私はUIViewアニメーションで作業しています。私はスクロールアップ中にビューを上下に移動したいと私は下にスクロールするときに移動する必要があります。UIViewアニメーションを使用してUIViewが適切にアニメーション化されない

- (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) { 

     }]; 

    } 
} 
+0

あなたの最初のif条件が何回も呼び出されます。アニメーションなしでビューフレームを変更し、ロジックが機能するかどうかを確認してください。 –

+0

最初にスクロールダウンしているときに条件が呼び出されたが、最初にビューコントローラに来てスクロールアップすると、他の部分がスクロールされます。最初はuiviewがジャンプし、elseブロックで定義した位置に移動します。 –

答えて

0

私は、ビューを上下に移動したい場合、非常に簡単だと思います。 スクロールビューでビューを追加すると、スクロールとともにビューを自動的に上下に移動できます。 scrollViewの "contentSize"プロパティを設定するだけです。

UICollectionViewのpanGestureを取得しようとしている場合、「scrollViewDidScroll」メソッドで取得できません。

UICollectionViewを使用したUIPanGestureRecognizerに関する便利なチュートリアルです。それが助けてくれることを願っています。

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

関連する問題