IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    iOS练手小APP之超级猜图(一)

    键盘上的舞者发表于 2015-06-13 19:36:31
    love 0

    效果图如上所示。

    点击放大的button,会有放大的动画效果,点击图片之外的区域,会有缩小的动画效果。

    点击图片会有放大的动画效果,点击放大之后的图片也由缩小的动画效果。

    细节方面就是图片放大的时候,后面的背景会慢慢加深,缩小的时候,背景会慢慢变浅。

    优化的地方就是,后面的蒙版不需要每次都实例化一个对象,整个过程中只需要实例化一次就可以了。

    代码:

    //
    //  ViewController.m
    //  超级猜图
    //
    //  Created by 键盘上的舞者 on 15/6/14.
    //  Copyright (c) 2015年 键盘上的舞者. All rights reserved.
    //
    
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @property (nonatomic , strong) UIButton *covert;
    
    @end
    
    @implementation ViewController
    
    //调整状态栏颜色
    -(UIStatusBarStyle)preferredStatusBarStyle
    {
        return UIStatusBarStyleLightContent;
    }
    //控件的懒加载
    -(UIButton *)covert
    {
        if(_covert==nil)
        {
            //设置蒙版
            _covert=[[UIButton alloc] initWithFrame:self.view.bounds];
            _covert.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.5];
            [self.view addSubview:_covert];
            _covert.alpha=0.0;
            [_covert addTarget:self action:@selector(BigAndSmallImage:) forControlEvents:UIControlEventTouchUpInside];
        }
        return _covert;
    }
    
    //放大缩小处理
    - (IBAction)BigAndSmallImage:(id)sender {
        
        if(self.covert.alpha==0){//放大处理
            //设置放置图片的button放在最前面
            [self.view bringSubviewToFront:self.iconButton];
            
            //图片放大的动画
            CGFloat w=self.view.bounds.size.width;
            CGFloat h=w;
            CGFloat y=(self.view.bounds.size.height-h)*0.5;
            [UIView animateWithDuration:1.0 animations:^{
                self.iconButton.frame=CGRectMake(0, y, w, h);
                self.covert.alpha=1.0;
            }];
        }else{//缩小处理
            [UIView animateWithDuration:1.0 animations:^{
                //图片缩小
                self.iconButton.frame=CGRectMake(82, 96, 150, 150);
                self.covert.alpha=0.0;
            }];
        }
        
        
        
        
    }
    @end



沪ICP备19023445号-2号
友情链接