1.先用归档创建arch文件保存好图片位置
2.在工程中提取控件位置
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic)int count;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSData *data = [NSData dataWithContentsOfFile:@"/Users/kyle/Desktop/layout_0.arch"];
NSArray *views = [NSKeyedUnarchiver unarchiveObjectWithData:data];
for (int i=0;i<views.count;i++) {
UIView *v = views[i];
UIImageView *iv = [[UIImageView alloc]initWithFrame:v.frame];
iv.p_w_picpath = [UIImage p_w_picpathNamed:[NSString stringWithFormat:@"%d.jpg",i]];
//给控件加边框
iv.layer.borderWidth= 1;
[self.viewaddSubview:iv];
}
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(changeLayout) userInfo:nil repeats:YES];
}
-(void)changeLayout{
NSString *path = [NSString stringWithFormat:@"/Users/kyle/Desktop/layout_%d.arch",++self.count%3];
NSData *data = [NSDatadataWithContentsOfFile:path];
NSArray *newViews = [NSKeyedUnarchiverunarchiveObjectWithData:data];
NSArray *p_w_picpathViews = self.view.subviews;
for (int i=0; i<p_w_picpathViews.count; i++) {
UIImageView *iv = p_w_picpathViews[i];
UIView *newView = newViews[i];
[UIView animateWithDuration:1 animations:^{
iv.frame = newView.frame;
}];
}
}