IOS開發之——超級猜圖之放大圖片(43)

一 概述

本文要實現超級猜圖程序,包含以下功能:

  • 根據圖片猜名字,猜對了金幣增加進入下一題,猜錯了金幣減少,並且名字變紅

  • 提示:提示當前題目的第一個字

  • 大圖:放大圖片,點擊其他位置縮小圖片

  • 下一題:跳過當前題目

<!--more-->

 

二 功能演示(大圖)

  • 點擊大圖按鈕,圖片放大,背景變暗

  • 點擊其他部分,圖片縮小到原來大小

     

三 代碼實現

3.1 ViewController.m

#import "ViewController.h"
​
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *iconButton;
@property (nonatomic,strong) UIButton *cover;
@end
@implementation ViewController
​
- (UIButton *)cover
{
    if (_cover==nil) {
​
        _cover=[[UIButton alloc]initWithFrame:self.view.bounds];
        _cover.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.5];
        [self.view addSubview:_cover];
        _cover.alpha=0.0;
        [_cover addTarget:self action:@selector(smallImage:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cover;
}
//放大圖片
- (IBAction)bigImage:(UIButton *)sender
{
    //1.添加蒙版(遮罩)
    [self cover];
    //2.將圖像按鈕放到最前面
    [self.view bringSubviewToFront:self.iconButton];
    //3.動畫放大圖像按鈕
    CGFloat w=self.view.bounds.size.width;
    CGFloat h=w;
    CGFloat y=(self.view.bounds.size.height-h)*0.5;
    [UIView animateWithDuration:1.0f animations:^{
         self.iconButton.frame=CGRectMake(0,y, w, h);
        self.cover.alpha=1.0;
    }];
}
​
//縮小圖片
-(void)smallImage:(UIButton *)cover
{
    //將圖像恢復初始位置
    [UIView animateWithDuration:1.0 animations:^{
        self.iconButton.frame=CGRectMake(112, 160, 150, 150);
        cover.alpha=0.0;
    } completion:^(BOOL finished) {
        //刪除cover
       //[cover removeFromSuperview];
    }];   
}
​
@end
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章