用于在事件中通过sender.tag确定是哪个控件传出的消息
UIView不能直接修改本身的frame、bounds、center来改变自身的位置、大小只能先将其取出来,然后修改,最后赋值进去
e.g.:
CGRect rect = self.headImageView.frame; // 1. 取值
rect.origin.y -= kMovingDelta; // 2. 修改
self.headImageView.frame = rect; // 3. 赋值
[UIView beginAnimations:nil context:nil];// 开始动画
[UIView setAnimationDelay:2.0]; // 设置动画延迟时间
self.headImageView.bounds = rect; // 需要伴随着动画的代码写在这里
self.headImageView.alpha = 0.5;
[UIView commitAnimations]; // 提交动画(开始动画)
-(void) viewDidLoad {
UIButton *btn = [[UIButton alloc] init];
btn.frame = CGRectMake(20, 20, 100, 100); // 指定位置
[btn setTitle: @"点我啊" forState:UIControlStateNormal];
[btn setBackgroundImage:[UIImage imageNamed: @"btn_01"] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor cyanColor] forState:UIControlStateNormal];
[btn setTitle: @"摸我啊" forState:UIControlStateHighlighted];
[btn setBackgroundImage:[UIImage imageNamed: @"btn_02"] forState:UIControlStateHighlighted];
[self.view addSubview: btn]; // 添加视图
}
-(void) tomAnimation:(NSString *) img count:(int) count
{
if ([self.tom isAnimating]) return;
NSMutableArray *array = [NSMutableArray array];
for (int i = 0; i < count; i++) {
NSString *imageName = [NSString stringWithFormat:@"%@_%02d", img, i];
NSString *path = [[NSBundle mainBundle] pathForResource:imageName ofType:@"jpg"];
UIImage *image = [UIImage imageWithContentsOfFile: path];
[array addObject:image];
}
[self.tom setAnimationImages:array];
[self.tom setAnimationDuration: count * 0.075];
[self.tom setAnimationRepeatCount: 1];
[self.tom startAnimating]; //开始动画
[self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.tom.animationDuration]; // 在动画结束后清除缓存
}
-(NSArray *) appList
{
if (!_appList) {
NSString *path = [[NSBundle mainBundle] pathForResource:@"app" ofType:@"plist"];
NSArray *array = [NSArray arrayWithContentsOfFile: path];
NSMutableArray *arrayM = [NSMutableArray array];
for (NSDictionary *dict in array) {
AppInfo *appInfo = [AppInfo appInfoWithDict:dict];
[arrayM addObject:appInfo];
}
_appList = arrayM;
}
return _appList;
}
NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"AppInfoView" owner:nil options:nil]; // 加载xib
UIView *appView = [array firstObject];
appView.frame = CGRectMake(x, y, viewWidth, viewHeight);
[self.view addSubview: appView];
UIImageView *imageView = (UIImageView *)[appView viewWithTag:1];
+(void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
参数解析:
+(void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
参数解析:
+(void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion
方法调用完毕后,相当于执行了下面两句代码:
// 添加toView到父视图
[fromView.superview addSubview:toView];
// 把fromView从父视图中移除
[fromView.superview removeFromSuperview];
参数解析:
UIImageView可以让一系列的图片在特定的时间内按顺序显示
相关属性解析:
相关方法解析:
UIActivityIndicatorView是一个旋转进度轮,可以用来告知用户有一个操作正在进行中,一般用initWithActivityIndicatorStyle初始化
方法解析:
UIActivityIndicatorViewStyle有3个值可供选择:
UIActivityIndicatorViewStyleWhiteLarge //大型白色指示器
UIActivityIndicatorViewStyleWhite //标准尺寸白色指示器
IUIActivityIndicatorViewStyleGray //灰色指示器,用于白色背景
新建
视图
运行
排版
[self setValue:dict[@"answer"] forKeyPath:@"answer"];
[self setValue:dict[@"title"] forKeyPath:@"title"];
[self setValue:dict[@"icon"] forKeyPath:@"icon"];
[self setValue:dict[@"options"] forKeyPath:@"options"];
要注意模型对象类中的属性与plist文件中字段要相同,否则会报错
- 第二种方式
[self setValuesForKeysWithDictionary:dict];
在Xcode6.3中选择新建Objective-c File, 在File Type中选择Category,在Class中选择NSArray,File随便写
然后在m文件中重写(NSString *) descriptionWithLocale:(id)locale方法
-(NSString *) descriptionWithLocale:(id)locale
{
NSMutableString *strM = [NSMutableString string];
[strM appendString:@"{\n"];
for (id obj in self) {
[strM appendFormat:@"\t%@,\n", obj];
}
[strM appendString:@"}"];
return strM;
}