IOS开发程序员iOS && Android

类似于新浪发微博的SheetItem动画

2016-05-30  本文已影响298人  那一片阳光

参考了网上几个类似做法
很简单的写了一个类似新浪一个弹出选择的sheetItem动画
下面就把这个动画的大概思路说一下

1.创建button的时候的布局

这里的布局调用了一个网上的一个方法,感觉不错,嫖来用一用
- (CGRect)getFrameWithItemCount:(NSInteger)itemCount
              perRowItemCount:(NSInteger)perRowItemCount
            perColumItemCount:(NSInteger)perColumItemCount
                    itemWidth:(CGFloat)itemWidth
                   itemHeight:(NSInteger)itemHeight
                     paddingX:(CGFloat)paddingX
                     paddingY:(CGFloat)paddingY
                      atIndex:(NSInteger)index
                       onPage:(NSInteger)page
{
      //
      NSUInteger rowCount = itemCount / perRowItemCount + (itemCount % perColumItemCount > 0 ? 1 : 0);
      
      //计算每个空间的Y
      CGFloat insetY = (CGRectGetHeight(self.bounds) - (itemHeight + paddingY) * rowCount) -200;
      
      CGFloat originY = ((index / perRowItemCount) - perColumItemCount * page) * (itemHeight + paddingY) + paddingY;
      
      //计算每个控件的x
      
      CGFloat originX = (index % perRowItemCount) * (itemWidth + paddingX) + paddingX + (page * CGRectGetWidth(self.bounds));
      
      CGRect itemFrame = CGRectMake(originX, originY + insetY, itemWidth, itemHeight);
      
      return itemFrame;
}

2.显示button的时候弹性动画,(很简单)

- (void)initailzerAnimationWithToPostion:(CGRect)toRect withView:(UIView *)view beginTime:(CFTimeInterval)beginTime {
 //一个点到另一个点的动画
 [UIView animateWithDuration:1.0 delay:beginTime usingSpringWithDamping:0.6 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
     view.frame = toRect;
 } completion:^(BOOL finished) {
     
 }];
}

3.for循环,显示和消失button(具体的代码 看demo)

总体来说把思路理清还是很简单的,没有涉及到难懂的知识点!DEMO不足之处,请多多指出!

上一篇 下一篇

猜你喜欢

热点阅读