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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值