#import "YYViewController.h"
@interface YYViewController ()
@property(nonatomic,strong)NSArray *apps;//声明用strong
@end
@implementation YYViewController
//1.加载数据 懒加载方法
- (NSArray *)apps
{
if (!_apps) {
//plist文件 将数据分离解耦合
NSString *path=[[NSBundle mainBundle]pathForResource:@"app.plist" ofType:nil];
_apps=[NSArray arrayWithContentsOfFile:path];
}
return _apps;
}
//2.完成布局设计
//三列
int totalloc=3;
CGFloat appvieww=80;
CGFloat appviewh=90;
CGFloat margin=(self.view.frame.size.width-totalloc*appvieww)/(totalloc+1);//算出边距
int count=self.apps.count;//将个数赋值
for (int i=0; i<count; i++) {
int row=i/totalloc;//行号
//1/3=0,2/3=0,3/3=1;
int loc=i%totalloc;//列号
CGFloat appviewx=margin+(margin+appvieww)*loc;//动态获取x坐标
CGFloat appviewy=margin+(margin+appviewh)*row;//动态获取y坐标
...
}
-(void)click
{
//动画标签
UILabel *animalab=[[UILabel alloc]initWithFrame:CGRectMake(self.view.center.x-100, self.view.center.y+20, 200, 40)];
[animalab setText:@"下载成功"];
animalab.font=[UIFont systemFontOfSize:12.0];
[animalab setBackgroundColor:[UIColor brownColor]];
[animalab setAlpha:0];//设置其初始化状态为全透明
[self.view addSubview:animalab];
// [UIView beginAnimations:Nil context:Nil]; //从下面的内容开始将其加入动画
// [animalab setAlpha:1];
// [UIView setAnimationDuration:4.0];
// [UIView commitAnimations];
//执行完之后,还得把这给删除了,推荐使用block动画
[UIView animateWithDuration:4.0 animations:^{
[animalab setAlpha:1];
} completion:^(BOOL finished) {
//[self.view re];
}];
}
iOS开发UI篇—九宫格坐标计算知识点提取
最新推荐文章于 2021-05-30 23:32:11 发布