• 九宫格图片浏览器


    #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
  • 相关阅读:
    System.InvalidOperationException异常的处理!vs15版
    五子棋项目的实现(四)具体的总结
    五子棋项目的实现(三)人机对战类的具体设计
    五子棋项目的实现(二)博弈树算法的描述
    五子棋项目的实现(一)
    java Exception和Error的区别
    java内存分配实例
    expdp与impdp
    SQL*PLUS下使用AUTOTRACE、sql顾问、实时sql监控
    Linux下如何将数据库脚本文件从sh格式变为sql格式
  • 原文地址:https://www.cnblogs.com/zhangyunjiang-love/p/5233565.html
Copyright © 2020-2023  润新知