iOS开发UI篇—九宫格坐标计算知识点提取

6 篇文章 0 订阅
#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];
    }];
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值