zoukankan      html  css  js  c++  java
  • 九宫格图片浏览器

    #import "ViewController.h"
    #import "Appfz.h"
    @interface ViewController ()
    @property(nonatomic,copy)NSArray *apps;//文件读取
    @property(nonatomic,assign)BOOL b;//判断属于放大还是缩小方法
    @property(nonatomic,assign)CGRect cgr;//记录按钮按下时的按钮的坐标、尺寸
    -(NSArray *)apps;//
    @end

    @implementation ViewController
    //数据读取
    -(NSArray *)apps
    {
        if (_apps==nil) {
        NSString *path=[[NSBundle mainBundle]pathForResource:@"myhous.plist" ofType:nil];
        NSArray *arr=[NSArray arrayWithContentsOfFile:path];
        NSMutableArray *arrM=[NSMutableArray array];
        for (NSDictionary *dic in arr) {
            Appfz *app=[Appfz appWithdic:dic];
            [arrM addObject:app];
            }
        _apps=arrM;
        }
        return _apps;
    }
    - (void)viewDidLoad {
        [super viewDidLoad];
        //基本数据
        int index=4;
        CGFloat appW=95;
        CGFloat appH=95;
        CGFloat apptopY=30;
        CGFloat appjxX=(self.view.frame.size.width-index*appW)/(index+1);
        CGFloat appjxY=appjxX;
        for (int i=0; i<self.apps.count; i++) {
            int X=i/index;
            int Y=i%index;
            Appfz *app1=self.apps[i];
            //循环添加按钮
            UIButton *app=[[UIButton alloc]init];
            app.frame=CGRectMake(appjxX+(appW+appjxX)*Y,apptopY+(appH+appjxY)*X+appjxY, appW, appH);
            [app setBackgroundImage:[UIImage imageNamed:app1.icon] forState:UIControlStateNormal];
            [app setBackgroundImage:[UIImage imageNamed:app1.icon] forState:UIControlStateHighlighted];
            [self.view addSubview:app];
            [app addTarget:self action:@selector(isbutton:) forControlEvents:UIControlEventTouchDown];
            }
        }
    //定义按钮方法
    -(IBAction)isbutton:(UIButton *)app
    {
        if (self.b==NO) {
            //在放大之前将按钮的大小尺寸赋值给self.cgr
            self.cgr=app.frame;
            [self button:app];
        }
        else
        {
            [self smallImgClick:app];}
    }
    //放大图像
    -(void)button:(UIButton *)app
    {
        [UIView animateWithDuration:1.0 animations:^{
            app.frame=CGRectMake(0, 30, 414, 706);
        }];
        [self.view bringSubviewToFront:app];
        //放大后不再放大
        self.b=YES;
    }
    //图像还原
    -(void)smallImgClick:(UIButton *)app1
    {
            [UIView animateWithDuration:1.0 animations:^{
               app1.frame=self.cgr;
            }];
        [self.view bringSubviewToFront:app1];
        self.b=NO;
    }
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    @end
  • 相关阅读:
    九个合理的个人所得税避税方案
    百度搜索技巧
    jsoup方法string转document
    java正则
    多线程之join方法
    java获取当前日期时间代码总结
    Error与Exception的区别,Java常见异常Execption总结
    Google Chrome调试js入门
    Resource temporarily unavailable用户的连接数设置的太小
    所有javax包
  • 原文地址:https://www.cnblogs.com/zhangyunjiang-love/p/5233565.html
Copyright © 2011-2022 走看看