iOS 切换动画cardSlider类型
2019-08-16 本文已影响0人
行走在北方
[self setupViews];
-(void)setupViews
{
__weak typeof(&*self)weakSelf = self;
if (_redIV) {
[_redIV removeFromSuperview];
}
_redIV = [[UIImageView alloc] init];
[_redIV setBackgroundColor:[UIColor redColor]];
[self.view addSubview:_redIV];
[_redIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(weakSelf.view);
make.centerY.mas_equalTo(weakSelf.view);
make.width.mas_equalTo(200);
make.height.mas_equalTo(200);
}];
[_imageArray insertObject:_redIV atIndex:0];
if (_blueIV) {
[_blueIV removeFromSuperview];
}
_blueIV = [[UIImageView alloc] init];
[_blueIV setBackgroundColor:[UIColor blueColor]];
[self.view addSubview:_blueIV];
[_blueIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(weakSelf.view);
make.centerY.mas_equalTo(weakSelf.view).offset(-20);
make.width.mas_equalTo(200);
make.height.mas_equalTo(200);
}];
[_imageArray insertObject:_blueIV atIndex:1];
CGAffineTransform transform = CGAffineTransformMakeScale(1, 1);
_blueIV.transform = CGAffineTransformScale(transform, 0.9, 0.9);
if (_greenIV) {
[_greenIV removeFromSuperview];
}
_greenIV = [[UIImageView alloc] init];
[_greenIV setBackgroundColor:[UIColor greenColor]];
[self.view addSubview:_greenIV];
[_greenIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(weakSelf.view);
make.centerY.mas_equalTo(weakSelf.view).offset(-40);
make.width.mas_equalTo(200);
make.height.mas_equalTo(200);
}];
[_imageArray insertObject:_greenIV atIndex:2];
CGAffineTransform transformGreen = CGAffineTransformMakeScale(1, 1);
_greenIV.transform = CGAffineTransformScale(transformGreen, 0.8, 0.8);
[self.view bringSubviewToFront:[_imageArray objectAtIndex:0]];
[[_imageArray objectAtIndex:1] exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
[self.view sendSubviewToBack:[_imageArray objectAtIndex:2]];
}
-(void)changePoint:(UIView*)pointView upView:(UIView*)upView andchangeVale:(CGFloat)changeValue
{
__weak typeof(&*self)weakSelf = self;
[pointView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(upView);
make.centerY.mas_equalTo(upView).offset(+20*changeValue);
make.width.mas_equalTo(200);
make.height.mas_equalTo(200);
}];
}
-(void)buttonClick
{
NSMutableArray *exchangeArray = [NSMutableArray array];
[_tempArray insertObject:[_imageArray objectAtIndex:1] atIndex:0];
[_tempArray insertObject:[_imageArray objectAtIndex:2] atIndex:1];
[_tempArray insertObject:[_imageArray objectAtIndex:0] atIndex:2];
if (_imageArray) {
[_imageArray removeAllObjects];
}
_imageArray = [NSMutableArray arrayWithArray:_tempArray];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[_tempArray objectAtIndex:2].alpha = 0.1;
[UIView animateWithDuration:1 animations:^{
[self.view bringSubviewToFront:[_tempArray objectAtIndex:0]];
[[_tempArray objectAtIndex:1] exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
[self.view sendSubviewToBack:[_tempArray objectAtIndex:2]];
[self changePoint:[_tempArray objectAtIndex:0] upView:self.view andchangeVale:0];
[self changePoint:[_tempArray objectAtIndex:1] upView:self.view andchangeVale:-1];
[self changePoint:[_tempArray objectAtIndex:2] upView:self.view andchangeVale:-2];
[self changeScaleWithUIView:[_tempArray objectAtIndex:0] andScaleVale:1];
[self changeScaleWithUIView:[_tempArray objectAtIndex:1] andScaleVale:0.9];
[self changeScaleWithUIView:[_tempArray objectAtIndex:2] andScaleVale:0.8];
} completion:^(BOOL finished) {
[_tempArray objectAtIndex:2].alpha = 1;
[_tempArray removeAllObjects];
_tempArray = [NSMutableArray array];
}];
});
}
-(void)changeScaleWithUIView:(UIView*)view andScaleVale:(CGFloat)scaleVale
{
CGAffineTransform transformGreen = CGAffineTransformMakeScale(1, 1);
view.transform = CGAffineTransformScale(transformGreen, scaleVale, scaleVale);
}
有用的小伙伴可以拿走
