• 自定义一个可以动态折叠的UITAbleViewCell


     看到code 4APP上有一个折叠的UITAbleViewCell,不过是swift的,所以自己尝试做一个简单的可折叠的UITAbleViewCell

    主要实现一个可以折叠的UITAbleViewCell

    效果图如下:

    用到下面这些知识点:

    1.单边圆角:

    我们经常会遇到一些情况需要进行单边圆角或者边界线的设置,我简单封装了一个类别,github网址

    2.锚点的更改

    项目中主要围绕view上边界进行3d旋转,所以在动画之前需要进行锚点的设置。

    关于锚点的详细概念,可以参考我的另一篇博客:点击这里

    因为锚点改变时,frame也会变动,所以在改变锚点时需要重新设置frame。

    我这里主要用下面的代码进行锚点的更改:

    - (void)setAnchorPointTo:(CGPoint)point view:(UIView*)view{
        
    /*    
     
        CGRect frame = view.frame;
        frame.origin.x+=(point.x - view.layer.anchorPoint.x) * view.frame.size.width;
        frame.origin.y+=(point.y - view.layer.anchorPoint.y) * view.frame.size.height;
        view.frame = frame;
        view.layer.anchorPoint = point;
     
    */
        //和上面注销掉的代码一个意思
        view.frame = CGRectOffset(view.frame, (point.x - view.layer.anchorPoint.x) * view.frame.size.width, (point.y - view.layer.anchorPoint.y) * view.frame.size.height);
        view.layer.anchorPoint = point;
    }

    3.旋转动画;

    关于旋转动画,我用的是下面的方法:

    [UIView animateWithDuration:0.3 animations:^{
            self.ThirdView.layer.transform=CATransform3DMakeRotation(M_PI_2, 1, 0, 0);
            
        }completion:^(BOOL finished) {
    
    
    }];

    当然你也可以用这个方法:

        CABasicAnimation* rotationAnimation;
        rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];
        [self setAnchorPointTo:CGPointMake(0.5, 0) view:self.secondView];
        rotationAnimation.fromValue = [NSNumber numberWithFloat: M_PI ];
        rotationAnimation.toValue = [NSNumber numberWithFloat: 0 ];
        rotationAnimation.duration = 3;
        rotationAnimation.cumulative = YES;
        rotationAnimation.repeatCount = 1;

    4.md34

    利用md34属性进行类似于翻页效果的设置,关于md34属性网上有很多文章说明,这里不做详细解释。

    具体代码为:

    //给containView添加偏移
        CATransform3D transfrom3d = CATransform3DIdentity;
        transfrom3d.m34 = -0.002;
        self.InnerView.layer.sublayerTransform = transfrom3d;

    5.阴影:

    -(void)setShadow:(UIView*)targetView{
        //阴影
        targetView.layer.shadowOpacity = 1.0;// 阴影透明度
        targetView.layer.shadowColor = [UIColor grayColor].CGColor;// 阴影的颜色
        targetView.layer.shadowRadius = 3;// 阴影扩散的范围控制
        targetView.layer.shadowOffset  = CGSizeMake(3, 3);// 阴影的范围
    }

     Demo地址:点击这里

    有什么bug,还请告知。

  • 相关阅读:
    内置函数
    递归函数:
    函数(迭代器与生成器)
    函数的装饰器
    函数:(函数的名字,闭包)
    函数(命名空间,作用域,嵌套)
    函数:(定义,调用,返回值和参数)
    hdu 4267 A Simple Problem with Integers(线段树)
    hdu 2089 不要62 hdu 3555 Bomb (数位DP)
    poj 2955 Brackets (区间DP)
  • 原文地址:https://www.cnblogs.com/sunjianfei/p/7095796.html
Copyright © 2020-2023  润新知