这段时间因为忙碌公司年会的事儿,已经有一个星期没有学习了,又加上休息了几天差不多10天的时间,没有动过iOS了,开始几天学习的知识差不多都忘得干干净净了。
学习真的时贵在坚持,只要超过3天不学习,想要再接着学,再找回原来的那种感觉没有好几天的时间是没办法做到的,到最后你真的很厌倦,真的不想再学了,特别是当自己在学习上没有什么成就感时,这种感觉就越发的凝实。
时间真的不多了,2015年已经过去,眨个眼睛2016年就过去了,我一定要把握好时间跟机遇,好好的利用现在有限的时间去努力达到自己的目标,为此坚持不懈!
第04天学习的主要内容有:
1、点击放大图片的代码示范:重点是设置遮盖层的思路
//1 点击放大图片
- (IBAction)bigImageClick {
//记录原始的frame
self.oldFrame = self.iconView.frame;
//1.1 放大图片
CGFloat iconW = self.view.frame.size.width;
CGFloat iconH = iconW;
CGFloat iconX = 0;
CGFloat iconY = (self.view.frame.size.height - iconH) / 2;
//1.3 生成遮盖的view (按钮)
UIButton *coverView = [UIButton buttonWithType:UIButtonTypeCustom];
[self.view addSubview:coverView];
self.coverView = coverView;
coverView.frame = self.view.bounds;
coverView.backgroundColor = [UIColor blackColor];
coverView.alpha = 0;
//1.4 把一个子控件置于顶层
[self.view bringSubviewToFront:self.iconView];
//1.2 动画
[UIView animateWithDuration:1.0 animations:^{
self.iconView.frame = CGRectMake(iconX, iconY, iconW, iconH);
coverView.alpha = 0.5;
}];
//1.5 点击遮盖层 缩小图片
[coverView addTarget:self action:@selector(smallImageClick) forControlEvents:UIControlEventTouchUpInside];
}
@interface CZQuestion : NSObject
@property (nonatomic,copy) NSString *answer;
@property (nonatomic,copy) NSString *icon;
@property (nonatomic,copy) NSString *title;
@property (nonatomic, strong) NSArray *options;
- (instancetype)initWithDic:(NSDictionary *)dic;
+ (instancetype)questionWithDic:(NSDictionary *)dic;
+ (NSArray *)questionsList;
@end
@implementation CZQuestion
- (instancetype)initWithDic:(NSDictionary *)dic
{
if (self = [super init]) {
self.answer = dic[@"answer"];
self.title = dic[@"title"];
self.icon = dic[@"icon"];
self.options = dic[@"options"];
}
return self;
}
+ (instancetype)questionWithDic:(NSDictionary *)dic
{
return [[self alloc] initWithDic:dic];
}
+ (NSArray *)questionsList
{
//加载plist
NSString *path = [[NSBundle mainBundle] pathForResource:@"questions" ofType:@"plist"];
NSArray *dicArray = [NSArray arrayWithContentsOfFile:path];
//字典转模型
NSMutableArray *tmpArray = [NSMutableArray array];
for (NSDictionary *dic in dicArray) {
CZQuestion *question = [CZQuestion questionWithDic:dic];
[tmpArray addObject:question];
}
return tmpArray;
}
@end
//2 懒加载
- (NSArray *)questions
{
if (_questions == nil) {
_questions = [CZQuestion questionsList];
}
return _questions;
}
4、隐藏状态栏:
- (BOOL)prefersStatusBarHidden
{
return YES;
}
在界面显示状态栏:
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
// 提供方法加载字典数据
- (instancetype) initWithDic:(NSDictionary *)dic
{
if (self = [super init]) {
// self.answer = dic[@"answer"];
// self.icon = dic[@"icon"];
// self.title = dic[@"title"];
// self.options = dic[@"options"];
// 代码简化
#pragma mark -- 10
// 设置字典中对应的键,赋给对象对应的属性,属性和字典必须一致
[self setValuesForKeysWithDictionary:dic];
}
return self;
}