寫在艱苦的日子裏。git
Github源碼地址:github.com/JonHory/Tra…github
經過modal進行轉場,設置modalTransitionStyle
爲UIModalTransitionStyleCrossDissolve
,設置modalPresentationStyle
爲UIModalPresentationOverFullScreen
api
外部只須要傳入一個外部的UIImageView
便可
1.建立一個UIImageView
和一個CGRect
來保存圖片信息和圖片frame信息。
使用- (CGRect)convertRect:(CGRect)rect toView:(nullable UIView *)view;
方法來獲取圖片的相對位置。
2.視圖將要出現時作動畫效果app
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[UIView animateWithDuration:AnimationTime animations:^{
//這裏能夠自由發揮了
self.view.backgroundColor = [UIColor greenColor];self.currentIV.frame = CGRectMake(0, 0, 200, 200); self.currentIV.center = CGPointMake(self.view.center.x, 200);
} completion:^(BOOL finished) {
}];
}複製代碼
3.返回的點擊事件處理動畫
- (void)back{
[UIView animateWithDuration:AnimationTime animations:^{
if ([self.type isEqualToString:@"vv"]) {
self.view.center = CGPointMake(self.view.center.x, self.view.bounds.size.height*1.5);
}else {
self.currentIV.frame = self.oldFrame;
self.view.backgroundColor = [UIColor clearColor];
}
} completion:^(BOOL finished) {
[self dismissViewControllerAnimated:NO completion:nil];
}];
}複製代碼
4.就這樣,效果就出來啦spa
用的是截屏的方法來實現背景縮小後置的效果
1.在當前UIViewController
用一個UIImageView
來保存截圖code
-(UIImage *)screenImageWithSize:(CGSize )imgSize{
UIGraphicsBeginImageContext(imgSize);
CGContextRef context = UIGraphicsGetCurrentContext();
AppDelegate * app = (AppDelegate *)[UIApplication sharedApplication].delegate; //獲取app的appdelegate,便於取到當前的window用來截屏
[app.window.layer renderInContext:context];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}複製代碼
2.在下一個VC建立一個減方法,在當前VC中使用cdn
[self presentViewController:vc animated:NO completion:nil];
[UIView animateWithDuration:0.3 animations:^{
//當前VC下截圖的縮小效果
self.screenshot.bounds = CGRectMake(50, 50, SCREEN.width - 100, SCREEN.height - 100);
} completion:^(BOOL finished) {
//這就是減方法 =_= 動畫結束時,改變背景塊的frame
[vc changeBigView];
}];複製代碼
3.在下一個VC返回時,當前VC的截圖視圖移除。blog
[weakSelf.screenshot removeFromSuperview];複製代碼
4.這樣,BOSS直聘的動畫效果就出現了。事件