如何使用平滑动画垂直为集合视图设置动画

时间:2017-08-23 07:23:19

标签: ios cocoa-touch animation uicollectionview

任何人都可以回答一些示例代码,将uicollectionview垂直动画到底部。

<script>
    $('#savelayer').click(function() {
        $.ajax({
            type: 'POST',
            url: 'savelyr.php',
            data: 'slyrname='+$('#slyrname').val()+'&getdrawn='+$('#getdrawn').val(),
            success: function(msg) {
                console.log(msg);
            }
        });
        $.ajax({
            url: 'maplayers.php',
            success: function() {
                var s1 = document.createElement("script");
                s1.src = "src/ol/map.js";
                s1.innerHTML = null;
                document.getElementById("scripts").innerHTML = "";
                document.getElementById("scripts").appendChild(s1);
                console.log("Success 2");
            }
        });
    });
</script>

这会非常快速地滚动我的集合视图。我希望软件动画部分明智。 帮我看看。

提前致谢

2 个答案:

答案 0 :(得分:0)

首先,请确保设置集合视图数据源并委托如下。

collectionView.datasource = self;
collectionView.delegate = self;

接下来你必须检查集合数组不应该是nil。

如果所有条件都匹配,请尝试重新加载您的收藏视图。

[collectionView reloadData];

答案 1 :(得分:0)

这对我有帮助 - :

@property (nonatomic, assign) CGPoint scrollingPoint, endPoint;
@property (nonatomic, strong) NSTimer *scrollingTimer;
@property (nonatomic, assign) BOOL animationStarted;

//scroll with finite time interval
- (void)scrollSlowlyWithInterval:(NSNumber*)interval {
    CGFloat height = self.clViewImages.contentSize.height;
    animationStarted = YES;
    // Set the point where the scrolling stops.
    self.endPoint = CGPointMake(0, height-self.clViewImages.frame.size.height);
    // Assuming that you are starting at {0, 0} and scrolling along the x-axis.
    self.scrollingPoint = CGPointMake(0, 0);
    // Change the timer interval for speed regulation.
    self.scrollingTimer = [NSTimer scheduledTimerWithTimeInterval:[interval doubleValue] target:self selector:@selector(scrollSlowlyToPoint) userInfo:nil repeats:YES];
}

- (void)scrollSlowlyToPoint {
    [self.clViewImages setContentOffset:self.scrollingPoint animated:YES];
    // Here you have to respond to user interactions or else the scrolling will not stop until it reaches the endPoint.
    if (CGPointEqualToPoint(self.scrollingPoint, self.endPoint)) {
        [self.scrollingTimer invalidate];
        animationStarted = NO;
    }
    // Going one pixel to the right.
    CGFloat height = [UIScreen mainScreen].bounds.size.height/2;
    self.scrollingPoint = CGPointMake(self.scrollingPoint.x, self.scrollingPoint.y+height);
}

// scrolling to bottom without default animation 
-(void)scrollToBottom{
    NSInteger section = [self.clViewImages numberOfSections] - 1;
    NSInteger items = [self.clViewImages numberOfItemsInSection:section] - 1;
    NSIndexPath *indxPath = [NSIndexPath indexPathForItem:items inSection:section];
    [self.clViewImages scrollToItemAtIndexPath:indxPath atScrollPosition:UICollectionViewScrollPositionBottom animated:YES];
}

-(void)reloadCollectionView{
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.clViewImages reloadData];
        if(!animationStarted){
            [self scrollSlowlyWithInterval:[NSNumber numberWithDouble:0.50f]];
        }
});
}

感谢Chris

相关问题