//首先建立模型文件
QLLQuestion.hheQLLQuestion.m文件 #import <Foundation/Foundation.h> @interface QLLQuestion : NSObject
@property(nonatomic,copy)NSString *answer;
@property(nonatomic,copy)NSString *icon;
@property(nonatomic,copy)NSString *title;
@property(nonatomic,strong)NSArray *options;
-(instancetype)initWithDict:(NSDictionary *)dict;
+(instancetype)QuestionWithDict:(NSDictionary *)dict;
@end #import "QLLQuestion.h" @implementation QLLQuestion
- (instancetype)initWithDict:(NSDictionary *)dict
{
    self = [super init];
    if (self) {
        self.answer=dict[@"answer"];
        self.icon=dict[@"icon"];
        self.title=dict[@"title"];
        self.options=dict[@"options"];
    }
    return self;
} +(instancetype)QuestionWithDict:(NSDictionary *)dict{
    return [[self alloc] initWithDict:dict]; }
@end //
//  ViewController.m
//  01-超级猜图
//
// #import "ViewController.h"
#import "QLLQuestion.h"
@interface ViewController ()
- (IBAction)tip;
- (IBAction)help;
- (IBAction)bigImg;
- (IBAction)nextQuestion;
- (IBAction)iconClick;
/**
 *  待选项视图
 */
@property (weak, nonatomic) IBOutlet UIView *opintionView;
/**
 *  答案项视图
 */
@property (weak, nonatomic) IBOutlet UIView *answerView;
/**
 *  模型类
 */
@property(nonatomic,strong)NSArray *question;
/**
 *  初始化序号
 */
@property(nonatomic,assign)int index;
/**
 *  序号label
 */
@property (weak, nonatomic) IBOutlet UILabel *numLabel;
/**
 *  标题
 */
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
/**
 *  图片按钮
 */
@property (weak, nonatomic) IBOutlet UIButton *imageBtn;
/**
 *  下一题按钮
 */
@property (weak, nonatomic) IBOutlet UIButton *nextBtn;
/**
 *  阴影按钮
 */
@property (weak, nonatomic) IBOutlet UIButton *cover;
/**
 *  分数按钮
 */
@property (weak, nonatomic) IBOutlet UIButton *scoreBtn;
@end @implementation ViewController - (void)viewDidLoad {
    [super viewDidLoad];
    //初始化index
    self.index=-;
    [self nextQuestion];
}
/**
 *  延时加载
 */
-(NSArray *)question{
    if (_question==nil) {
        
        //引入plist文件
        NSArray *dicArray=[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"questions" ofType:@"plist"]];
        NSMutableArray *questonsAray=[NSMutableArray array];
        //取出模型
        for (NSDictionary *dict in dicArray) {
            QLLQuestion *quenstions=[[QLLQuestion alloc]initWithDict:dict];
            [questonsAray addObject:quenstions];
        }
        //赋值
        _question=questonsAray;
    }
    return  _question;
}
-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent; }
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/**
 *  下一题
 */
- (IBAction)nextQuestion {
    //增加索引
    self.index++;     //取出模型
    QLLQuestion *quenstion=self.question[self.index];
//    NSLog(@"%d",self.index);
    //设置数据
    [self settingDateWithQuenstion:quenstion];
    //设置答案项
    [self addAnswerBtn:quenstion];
    //设置待选项
    [self addOpinionBtn:quenstion];
}
/**
 *  设置数据
 */
-(void)settingDateWithQuenstion:(QLLQuestion *)quenstion{
    self.numLabel.text=[NSString stringWithFormat:@"%d/%lu",self.index+,self.question.count];
    self.titleLabel.text=quenstion.title;
    [self.imageBtn setImage:[UIImage imageNamed:quenstion.icon] forState:UIControlStateNormal];
    //设置下一个按钮的状态
    self.nextBtn.enabled=(self.index!=self.question.count-);
}
/**
 *  设置答案项
 */
-(void)addAnswerBtn:(QLLQuestion *)quenstion{     //删除之前的所有按钮
//    for (UIView *subView in self.answerView.subviews) {
//        [subView removeFromSuperview];
//    }
    [self.answerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    //设置答案按钮
    NSInteger length=quenstion.answer.length;
    for (int i=; i<length; i++) {
        UIButton *answerBtn=[[UIButton alloc]init];
        [self.answerView addSubview:answerBtn];
        //设置背景
        [answerBtn setBackgroundImage:[UIImage imageNamed:@"btn_answer"] forState:UIControlStateNormal];
        [answerBtn setBackgroundImage:[UIImage imageNamed:@"btn_answer_highlighted"] forState:UIControlStateHighlighted];
        [answerBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        //设置frame
        CGFloat margin=;
        CGFloat answerW=;
        CGFloat answerH=;
        CGFloat viewW=self.view.frame.size.width;
        CGFloat leftMargin=(viewW-length*answerW-(length-)*margin)*0.5;
        CGFloat answerX=leftMargin+i*(answerW+margin);
        answerBtn.frame=CGRectMake(answerX, , answerW, answerH);
        //监听答案按钮的点击
        [answerBtn addTarget:self action:@selector(answerClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.answerView addSubview:answerBtn];
    } }
/**
 *  监听答案按钮的点击
 */
-(void)answerClick:(UIButton *)answerBtn{
    //答案按钮的文字
//    NSString *answerTitle=[answerBtn titleForState:UIControlStateNormal];
    NSString *answerTitle=answerBtn.currentTitle;     //让答案按钮对应的待选项的文字显示出来
    for (UIButton *optionBtn in self.opintionView.subviews) {
        //待选项的文字
        NSString *optionTitle=[optionBtn titleForState:UIControlStateNormal];         if ([optionTitle isEqualToString:answerTitle] && optionBtn.hidden==YES) {
            optionBtn.hidden=NO;
            break;
        }
    }
//    NSLog(@"%d",self.index);     //让被点击的答案按钮文字消失
    [answerBtn setTitle:nil forState:UIControlStateNormal];
    //让所有的答案按钮变为黑色
    for (UIButton *answerBtn in self.answerView.subviews) {
        [answerBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
}
/**
 *  设置带选项
*/
-(void)addOpinionBtn:(QLLQuestion *)quenstion{
    //设置待选项
    //删除之前的按钮
    //让数组中所有的对象都调用removeFromSuperview
    [self.opintionView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
//    for (UIView *subview in self.opintionView.subviews) {
//        [subview removeFromSuperview];
//    }     NSInteger count=quenstion.options.count;
    for (int i=; i<count; i++) {
        //设置待选项的背景
        UIButton *optionBtn=[[UIButton alloc]init];
        [optionBtn setBackgroundImage:[UIImage imageNamed:@"btn_option"] forState:UIControlStateNormal];
        [optionBtn setBackgroundImage:[UIImage imageNamed:@"btn_option_highlighted"] forState:UIControlStateHighlighted];
        //设置文字
        [optionBtn setTitle:quenstion.options[i] forState:UIControlStateNormal];
        [optionBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        optionBtn.titleLabel.font=[UIFont systemFontOfSize:];
        
        NSInteger totalColumns=;
        //设置frame
        CGFloat margin=;
        NSInteger row=i/totalColumns;
        NSInteger col=i%totalColumns;
        CGFloat optionW=;
        CGFloat optionH=;
        CGFloat viewW=self.view.frame.size.width;
        CGFloat optionLeftMargin=(viewW-totalColumns*optionW-(totalColumns-)*margin)*0.5;
        
        CGFloat optionX=optionLeftMargin + col*(optionW+margin);
        CGFloat optionY=row*(optionH+margin);
        optionBtn.frame=CGRectMake(optionX,optionY , optionW, optionH);
        //监听待选按钮的点击
        [optionBtn addTarget:self action:@selector(optionClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.opintionView addSubview:optionBtn];
        
    } }
/**
 *  监听待选按钮的点击
 */
-(void)optionClick:(UIButton *)optionBtn{
    //让待选按钮消失
    optionBtn.hidden=YES;
    
    //显示文字到正确答案上
    for (UIButton *answerBtn in self.answerView.subviews) {
        //判断按钮是否有文字
        NSString *ansTitle= [answerBtn titleForState:UIControlStateNormal];
        if(ansTitle.length==){ //没有文字
            //设置答案按钮的文字为被点击待选按钮的文字
            NSString *optionTitle= [optionBtn titleForState:UIControlStateNormal];             [answerBtn setTitle:optionTitle forState:UIControlStateNormal];
            
            break;
        }
    }
    //判断答案是否填满
    BOOL full=YES;
    NSMutableString *tempAnswerTitle=[NSMutableString string];
    for (UIButton *answerBtn in self.answerView.subviews) {
        //判断按钮是否有文字
        NSString *ansTitle= [answerBtn titleForState:UIControlStateNormal];
        if(ansTitle.length==){ //没有文字
            
            full=NO;
        }
        //拼接文字
        if (ansTitle) {
            [tempAnswerTitle appendString:ansTitle];
        }
    }
    
    //答案满 了
    if (full) {
        QLLQuestion *quenstion=self.question[self.index];
        if ([tempAnswerTitle isEqualToString:quenstion.answer]) {   //答对了,文字蓝色
            for (UIButton *answerBtn in self.answerView.subviews) {
                [answerBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
            }
            //加分
            [self scoreDelta:];
            
            //跳到下一题
            [self performSelector:@selector(nextQuestion) withObject:nil afterDelay:0.25];         }else{
            for (UIButton *answerBtn in self.answerView.subviews) {
                [answerBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
            }
        }
    }
}
/**
 *  点击图片变大和变小
 */
- (IBAction)iconClick {
    
    if (self.cover==nil) {//要放大
        [self bigImg];
    }else{
        [self smallImg];
    }
}
/**
 *  提示
 */
- (IBAction)tip {
    //点击所有的答案按钮
    for (UIButton *answerBtn in self.answerView.subviews) {
        [self answerClick:answerBtn];
    }         //取出答案
        QLLQuestion *quenstions=self.question[self.index];
        
        //
        NSString *firstAnswer= [quenstions.answer substringToIndex:];
        
    for (UIButton *optionBtn in self.opintionView.subviews) {
        if ([optionBtn.currentTitle isEqualToString:firstAnswer]) {
            [self optionClick:optionBtn];
            break;
        }
    }
        //  扣分
    [self scoreDelta:-];
}
/**
 *  帮助
 */
- (IBAction)help {
}
-(void)scoreDelta:(int)delta{
    int score=self.scoreBtn.currentTitle.intValue;
    score+=delta;
    [self.scoreBtn setTitle:[NSString stringWithFormat:@"%d",score] forState:UIControlStateNormal];
}
/**
 *  大图
 */
- (IBAction)bigImg {
    
       //添加阴影
    UIButton *cover=[[UIButton alloc]init];
    cover.frame=self.view.bounds;
    cover.backgroundColor=[UIColor blackColor];
    cover.alpha=0.0;
    [cover addTarget:self action:@selector(smallImg) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:cover];
    self.cover=cover;
    
    //开始动画
  //更换阴影和头像的位置
//
//    [UIView beginAnimations:nil context:nil];
//    [UIView setAnimationDuration:1.0];
    [UIView animateWithDuration:0.5 animations:^{
        [self.view bringSubviewToFront:self.imageBtn];
        CGFloat iconW=self.view.frame.size.width;
        CGFloat iconH=iconW;
        CGFloat iconX=;
        CGFloat iconY=(self.view.frame.size.height-iconH)*0.5;
        self.imageBtn.frame=CGRectMake(iconX, iconY, iconW, iconH);
        cover.alpha=0.7;
    }];
  
         
    
//    [UIView commitAnimations];
}
/**
 *  小图
 */
-(void)smallImg{
    //动画的block
    
    [UIView animateWithDuration:0.5 animations:^{
        self.imageBtn.frame=CGRectMake(, , , );
        self.cover.alpha=0.0;
    } completion:^(BOOL finished) {
        [self.cover removeFromSuperview];
        self.cover=nil;
    }];
    
    
    
    //删除阴影
//    [self.cover removeFromSuperview];
//    self.cover=nil;;
    //缩小图片
//    [UIView beginAnimations:nil context:nil];
//    [UIView setAnimationDuration:1.0];
//    [UIView setAnimationDelegate:self];
//    [UIView setAnimationDidStopSelector:@selector(removeCover)];
//    self.imageBtn.frame=CGRectMake(97, 160, 220, 220);
//    
//    
//    self.cover.alpha=0.0;      //    [UIView commitAnimations];
    
    
}
//
//-(void)removeCover{
//    [self.cover removeFromSuperview];
//    self.cover=nil;
//}
@end

iOS实现(超级猜图)源码的更多相关文章

  1. iOS高仿app源码:纯代码打造高仿优质《内涵段子》

    iOS高仿app源码:纯代码打造高仿优质<内涵段子>收藏下来 字数1950 阅读4999 评论173 喜欢133 Github 地址 https://github.com/Charlesy ...

  2. 比较不错的一个ios找茬游戏源码

    找茬游戏源码 ,这个是一款非常不错的ios找茬游戏源码,该游戏的兼容性非常好的,并且还可以支持ipad和iphone,UI界面设计得也很漂亮,游戏源码真的是一款非常完美,而且又很完整的一款休闲类的游戏 ...

  3. ios水果风暴游戏源码下载

    游戏源码是从那个IOS教程网IOS.662p.com分享给大家的. 这是一款ios水果风暴游戏源码下载,介绍给大家一下,喜欢的朋友可以下载学习一下吧.应用介绍:这是一个以获得高分和挑战更高难度为目的的 ...

  4. ios水果风暴游戏源码项目下载

    这是一款ios水果风暴游戏源码下载,介绍给大家一下,喜欢的朋友可以下载学习一下吧.应用介绍:这是一个以获得高分和挑战更高难度为目的的游戏.游戏中有九种不同的卡通水果,您可以交换屏幕中两个相邻水果的位置 ...

  5. 仿陌陌的ios客户端+服务端源码项目

    软件功能:模仿陌陌客户端,功能很相似,注册.登陆.上传照片.浏览照片.浏览查找附近会员.关注.取消关注.聊天.语音和文字聊天,还有拼车和搭车的功能,支持微博分享和查找好友. 后台是php+mysql, ...

  6. iOS开发之Alamofire源码解析前奏--NSURLSession全家桶

    今天博客的主题不是Alamofire, 而是iOS网络编程中经常使用的NSURLSession.如果你想看权威的NSURLSession的东西,那么就得去苹果官方的开发中心去看了,虽然是英文的,但是结 ...

  7. iOS版打地鼠游戏源码

    打地鼠游戏源码,游戏是一款多关卡基于cocos2d的iPad打地鼠游戏源码,这也是一款高质量的打地鼠游戏源码,可以拥有逐步上升的关卡的设置,大家可以在关卡时设置一些商业化的模式来盈利的,非常完美的一款 ...

  8. 较好的IOS新闻客户端应用源码

    兼容性较好的新闻客户端应用源码,这个是一款国外新闻客户端源码,并且这款应用兼容性非常好的,可以很好地兼容iPhone和iPad的使用,而且应用的功能很多,新闻列表,上啦下拉刷新效果,评论列表,在线评论 ...

  9. ios球体弹跳游戏源码

    一款耐玩的ios游戏源码,画面上有很多小星星,球体落下的时候,你需要在画面上画出一条条的线条让球体弹跳起来然后吃掉小星星,如果没借助球体就失败了.游戏有很多关卡.注意: <ignore_js_o ...

随机推荐

  1. STL中的set/multiset小结

    (1)使用set/multiset之前必须包含头文件<set>:#include<set> (2)namespace std{ template <class T, cl ...

  2. ionic 实现自动升级APP

    最近做移动商城开发,需要一个自动升级APP的功能,在网上搜罗很多,发现有的是下载APK,有的在我这服务无法实现,由于时间原因,都被PASS了,最后找到了一个热更新插件,经过半天的调试,可以使用,很欣喜 ...

  3. 斜堆(二)之 C++的实现

    概要 上一章介绍了斜堆的基本概念,并通过C语言实现了斜堆.本章是斜堆的C++实现. 目录1. 斜堆的介绍2. 斜堆的基本操作3. 斜堆的C++实现(完整源码)4. 斜堆的C++测试程序 转载请注明出处 ...

  4. [OpenCV] Face Detection

    即将进入涉及大量数学知识的阶段,先读下“别人家”的博文放松一下. 读罢该文,基本能了解面部识别领域的整体状况. 后生可畏. 结尾的Google Facenet中的2亿数据集,仿佛隐约听到:“你们都玩儿 ...

  5. 使用WinDbg调试SQL Server查询

    上一篇文章我给你介绍了WinDbg的入门,还有你如何能附加到SQL Server.今天的文章,我们继续往前一步,我会向你展示使用WinDbg调试SQL Server查询需要的步骤.听起来很有意思?我们 ...

  6. Java中接口式的匿名内部类的构造方法

    在使用多线程的时候,时常会使用两种方式实现,一种是直接继承Thread类来实现多线程,另外一种就是实现Runnable接口. 我们都知道,接口是没有构造方法的,同时匿名内部类也是没有构造方法的.原因有 ...

  7. C#中方法的调用

    C#中方法的调用 1.同一个类中方法的调用: 静态方法可以直接调用静态方法 静态方法不能直接调用非静态方法,静态方法先生成. 非静态方法可以直接调用静态方法 如果静态方法要调用非静态的方法,必须使用实 ...

  8. JS代码放置位置、变量与数据类型、运算符与逻辑表达运算符

    内容简要: 1.JS代码放置位置的问题: 2.变量与数据类型: 3.运算符与逻辑表达式的运算符   我的位置 全局问题:为何在网页推荐位置(一般在<head></head>内部 ...

  9. 新的Visual C++代码优化器

    微软在 5 月 4 日发布了新的高级代码优化器,服务于 Visual C++ 的后端编译器.提高了代码性能,可以压缩代码体积,将编译器带入了一个新的境界. Visual C++ 的团队在博客上称,这将 ...

  10. 【C#】第1章 VS2015中C#6的新特性

    分类:C#.VS2015 创建日期:2016-06-12 一.简介 VS2015内置的C#版本为6.0,该版本提供了一些新的语法糖,这里仅列出个人感觉比较有用的几个新功能. 二.几个很有用的新特性 注 ...