iOS开发翻转动画效果

来源:互联网 发布:网络号码发短信 编辑:程序博客网 时间:2024/05/19 18:38


#import "TJNewsViewController.h"

#define DOT_COORDINATE    0.0f

#define ARROW_BUTTON_WIDTH 44.0f

@interfaceTJNewsViewController ()

{

    BOOL _popItemMenu;

}


@end

@implementation TJNewsViewController

-(void)viewDidLoad{

    [self initUI];

}

-(void)initUI{

    UIImageView * _arrowBtn = [[UIImageView alloc]initWithFrame:CGRectMake(DOT_COORDINATE,DOT_COORDINATE,ARROW_BUTTON_WIDTH,ARROW_BUTTON_WIDTH)];

    _arrowBtn.layer.shadowColor = [UIColor blackColor].CGColor;//shadowColor阴影颜色

    _arrowBtn.layer.shadowOffset =CGSizeMake(3,3);//shadowOffset阴影偏移,x向右偏移3y向下偏移3,默认(0, -3),这个跟shadowRadius配合使用

    _arrowBtn.image =[UIImage imageNamed:@"arrow.png"];

    _arrowBtn.userInteractionEnabled =YES;

    [self.viewaddSubview:_arrowBtn];

    [self viewShowShadow:_arrowBtn shadowRadius:22.0f shadowOpacity:1.0f];

    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(functionButtonPressed:)];

    [_arrowBtn addGestureRecognizer:tapGestureRecognizer];

}

#pragma mark - click

- (void)functionButtonPressed:(UITapGestureRecognizer*)tapGestureRecognizer

{

    _popItemMenu = !_popItemMenu;

    [self viewSubShow:tapGestureRecognizer.view popItemMenu:_popItemMenu];


}

#pragma mark - 阴影

- (void)viewShowShadow:(UIView *)view shadowRadius:(CGFloat)shadowRadius shadowOpacity:(CGFloat)shadowOpacity

{

    view.layer.shadowRadius = shadowRadius;//阴影半径,默认3

    view.layer.shadowOpacity = shadowOpacity;//阴影透明度,默认0

}

#pragma mark - 视图翻转

- (void)viewSubShow:(UIView *)view popItemMenu:(BOOL)pop

{

    if (pop)

    {

       [self viewShowShadow:view shadowRadius:DOT_COORDINATE shadowOpacity:DOT_COORDINATE];

        [UIView animateWithDuration:0.5f animations:^{

            view.transform =CGAffineTransformMakeRotation(M_PI);

        } completion:^(BOOL finished) {

        }];

    }

    else

    {

        [UIView animateWithDuration:0.5f animations:^{

            view.transform =CGAffineTransformIdentity;

        } completion:^(BOOL finished) {

            [self viewShowShadow:view shadowRadius:22.0f shadowOpacity:1.0f];

        }];

    }

}


@end


0 0
原创粉丝点击