IOS Auto Layout 二 -UIStackView

#pragma mark - 减少点击
-(void)btnReduceClick{
    [UIView animateWithDuration:0.5f
                          delay:0.0f
         usingSpringWithDamping:0.7f
          initialSpringVelocity:5.0f
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                            NSArray *subviewArrays = self.stackStars.arrangedSubviews;
                            if(subviewArrays.count != 0){
                                UIView* view = self.stackStars.arrangedSubviews.lastObject;
                                [self.stackStars removeArrangedSubview:view];
                                [view removeFromSuperview];
                            }
                     } completion:^(BOOL finished) {
                         
                     }];
}
#pragma mark - 增加点击
-(void)btnAddClick{
    [UIView animateWithDuration:0.5f
                          delay:0.0f
         usingSpringWithDamping:0.7f
          initialSpringVelocity:5.0f
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                            UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon_star"]];
                            imageView.contentMode = UIViewContentModeCenter;
                            [self.stackStars addArrangedSubview:imageView];
                     } completion:^(BOOL finished) {
                         
                     }];
}

参考文献:
iOS9之UIStackView体验,无需任何约束,这才是真正的自动布局,快到不能呼吸
An Introduction to Stack Views in iOS 9 and Xcode 7
iOS 9: UIStackView入门

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。