#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篇—九宮格座標計算知識點提取
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.