记录一个由于代码写错导致的一个掉咋天的动画

来源:互联网 发布:淘宝不错的睡衣店知乎 编辑:程序博客网 时间:2024/06/05 18:58

//  Copyright © 2017年 开太平研发1. All rights reserved.

//


#import "KtpShareAlertView.h"

#import <Masonry.h>



@interface KtpShareAlertView()<UICollectionViewDelegate,UICollectionViewDataSource>


@property ( nonatomic,strong ) UICollectionView * collectionView;

@property ( nonatomic, strong ) UIButton * cancelBtn;

@property ( nonatomic,strong ) UIView   * bottomSepLine;


@property ( nonatomic, strong ) UIControl  * mskView; //遮罩

@property ( nonatomic, strong ) UIView     * cntView;


@property ( nonatomic, strong ) NSArray * imageList;

@property ( nonatomic, strong ) NSArray * titleList;


@end


@implementation KtpShareAlertView


+ ( void ) show {

    

    KtpShareAlertView * shareAlertView = [[KtpShareAlertViewalloc] init];

    shareAlertView.frame =CGRectMake(0,0, [UIScreenmainScreen].bounds.size.width, [UIScreenmainScreen].bounds.size.height);

    [[UIApplicationsharedApplication].keyWindow addSubview:shareAlertView];

    

    [shareAlertView showWithAnimation];

}



- ( void ) showWithAnimation {

    

    CGAffineTransform transform =self.cntView.transform;

    self.cntView.transform =CGAffineTransformScale(transform, 0,kP(120));

    [UIView animateWithDuration:0.2delay:0 options:UIViewAnimationOptionCurveEaseInOut  animations:^{

        

        self.cntView.transform =CGAffineTransformScale(transform, 0,kP(-5));;

        

    } completion:^(BOOL finished) {

        

        [UIViewanimateWithDuration:0.2delay:0 options:UIViewAnimationOptionCurveEaseInOut  animations:^{

            

            self.cntView.transform = transform;

            

        } completion:^(BOOL finished) {

            

        }];

        

    }];

}


#pragma mark

#pragma mark

#pragma mark -- button 事件响应

- ( void ) mskBtnDidClicked:(UIControl *) sender {

    

    [selfremoveFromSuperview];

}


#pragma mark

#pragma mark

#pragma mark -- collectionView  delegate,datasource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

    

    return self.titleList.count;

}


- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    

    KtpShareItem * item = (KtpShareItem *)[collectionViewdequeueReusableCellWithReuseIdentifier:NSStringFromClass([KtpShareItemclass]) forIndexPath:indexPath];

    

    

    return item;

}


#pragma mark

#pragma mark

#pragma mark -- 生命周期

- ( instancetype ) init {

    

    self = [superinit];

    if( self ){

        

        [selfsetBaseAttribute];

        [selfsetupSubviews];

        [selfsetupSubviewsLayout];

    }

    return self;

}


- ( void ) setBaseAttribute {

    self.cntView.backgroundColor =KTPColor_White;

}


- ( void ) setupSubviews {

    

    [selfaddSubview:self.collectionView];

    [selfaddSubview:self.cancelBtn];

    [selfaddSubview:self.bottomSepLine];

    [selfaddSubview:self.mskView];

    [selfaddSubview:self.cntView];

}


- ( void ) setupSubviewsLayout {

    

    [self.mskViewmas_makeConstraints:^(MASConstraintMaker *make) {

        make.edges.equalTo(self);

    }];

    

    [self.cntViewmas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.right.bottom.equalTo(self);

        make.height.mas_equalTo(kP(120));

    }];

    

    [self.collectionViewmas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.top.right.equalTo(self.collectionView);

        make.height.mas_equalTo(kP(80));

    }];

    

    [self.cancelBtnmas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.equalTo(self.collectionView.mas_bottom);

        make.centerX.equalTo(self.collectionView);

    }];

    

    [self.bottomSepLinemas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.right.equalTo(self.cancelBtn);

        make.height.equalTo(@1);

        make.top.equalTo(self.cancelBtn.mas_bottom);

    }];

}


#pragma mark

#pragma mark

#pragma mark -- subviews create

- ( UICollectionView * ) collectionView {

    

    if ( !_collectionView ) {

        

        UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayoutalloc] init];

        

        _collectionView = [[UICollectionViewalloc] initWithFrame:CGRectZerocollectionViewLayout:layout];

        _collectionView.delegate =self;

        _collectionView.dataSource =self;

        [_collectionViewregisterClass:[KtpShareItemclass] forCellWithReuseIdentifier:NSStringFromClass([KtpShareItemclass])];

    }

    return_collectionView;

}


- ( UIButton * ) cancelBtn {

    

    if ( !_cancelBtn ) {

        _cancelBtn = [UIButtonbuttonWithType:0];

        [_cancelBtnsetTitle:@"取消"forState:UIControlStateNormal];

        [_cancelBtnsetTitleColor:KTPTextColor3forState:UIControlStateNormal];

        _cancelBtn.titleLabel.font =KTPFont_Fit(16);

    }

    return_cancelBtn;

}



- ( UIControl * ) mskView {

    

    if( !_mskView ){

        _mskView = [[UIControlalloc] init];

        _mskView.backgroundColor = [[UIColorblackColor] colorWithAlphaComponent:0.6];

        [_mskViewaddTarget:selfaction:@selector(mskBtnDidClicked:)forControlEvents:UIControlEventTouchUpInside];

    }

    return_mskView;

}


- ( UIView * ) cntView {

    

    if( !_cntView ){

        _cntView = [[UIViewalloc] init];

    }

    return_cntView;

}



- ( UIView * ) bottomSepLine {

    

    if( !_bottomSepLine ){

        _bottomSepLine = [[UIViewalloc] init];

    }

    return_bottomSepLine;

}



- ( NSArray * ) titleList {

    

    if ( !_titleList ) {

        _titleList =@[@"朋友圈",@"微信好友",@"QQ好友"];

    }

    return_titleList;

}


- ( NSArray * ) imageList {

    

    if ( !_imageList ) {

        _imageList =@[@"fieldManagementSelect",@"fieldManagementSelect",@"fieldManagementSelect"];

    }

    return_imageList;

}


@end







#pragma mark

#pragma mark

#pragma mark -- KtpShareItem

@interface KtpShareItem()


@property ( nonatomic, strong ) UIImageView * iconView;

@property ( nonatomic, strong ) UILabel * titleLabel;


@end



@implementation KtpShareItem


#pragma mark

#pragma mark

#pragma mark -- setting

- ( void ) setTitle:(NSString *)title {

    

    self.titleLabel.text = title;

}


- ( void ) setImageName:(NSString *)imageName {

    

    self.iconView.image = [UIImageimageNamed:imageName];

}


#pragma mark

#pragma mark

#pragma mark -- 生命周期

- ( instancetype ) init {

    

    self = [superinit];

    if( self ){

        

        [selfsetBaseAttribute];

        [selfsetupSubviews];

        [selfsetupSubviewsLayout];

    }

    return self;

}


- ( void ) setBaseAttribute {

    

}


- ( void ) setupSubviews {

    

    [self.contentViewaddSubview:self.iconView];

    [self.contentViewaddSubview:self.titleLabel];

}


- ( void ) setupSubviewsLayout {

    

    [self.iconViewmas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerX.equalTo(self.contentView);

        make.top.equalTo(self.contentView).offset(kP(10));

        make.height.mas_equalTo(kP(30));

        make.width.equalTo(self.iconView.mas_height);

    }];

    

    [self.titleLabelmas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerX.equalTo(self.contentView);

        make.top.equalTo(self.iconView.mas_bottom).offset(kP(8));

    }];

}


#pragma mark

#pragma mark

#pragma mark -- subviews create

- ( UIImageView * ) iconView {

    

    if ( !_iconView ) {

        _iconView = [[UIImageViewalloc] init];

    }

    return_iconView;

}


- ( UILabel * ) titleLabel {

    

    if ( !_titleLabel ) {

        _titleLabel = [[UILabelalloc] init];

        _titleLabel.font =KTPFont_Fit(16);

        _titleLabel.textColor =KTPTextColor1;

    }

    return_titleLabel;

}


@end




原创粉丝点击