zoukankan      html  css  js  c++  java
  • 返回上一视图,凸显一个视图,其他视图变模糊

    //

    //  AchievementViewController.m

    //  LIBAOZHENG0826

    //

    //  Created by 张艳锋 on 15/8/27.

    //  Copyright (c) 2015年 张艳锋. All rights reserved.

    //

    #import "AchievementViewController.h"

    #import "LBZModelDataAll.h"

    #import "LBZPrefixHeader.pch"

    @interface AchievementViewController ()

    {

        __weak IBOutlet UIScrollView *ZYFachievementscrollView;

        UIView *PoetIntroduceview;

        UIView *bgview;

    }

    - (IBAction)ZYFdoBackButton:(id)sender;

    @end

    @implementation AchievementViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        self.view.backgroundColor=[UIColor brownColor];//设置背景色

        [self button];//调用button方法

    }

     

    - (IBAction)ZYFdoBackButton:(id)sender {

        [self dismissViewControllerAnimated:YES completion:nil];//返回上一页面

    }

    -(void)button{

        NSArray *arrbutton=[LBZModelDataAll dataArrayFromModel:poet_list];//从宏定义中抽取数据

        NSLog(@"%lu",(unsigned long)arrbutton.count);

        for (int i=0; i<arrbutton.count; i++) {

            NSLog(@"%@",[LBZModelDataAll dataDetailFromModel:poet_list andDataNum:i andNSString:poet_id]);

    //自动生成button

            UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(110*(i%5)+30,150*(int)(i/5), 80, 138)];

            button.tag=i;//添加tag值方便点击时知道点击的是哪一个

            UIImageView *figurephoto=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 80, 138)];

             figurephoto.image=[UIImage imageNamed:@"card_back_new1.png"];//在按钮上面添加图片不会影响按钮的使用,

           [button addSubview:figurephoto];

            

            

            //诗人名字标签(初始化规格,获取数据,设置标签字体大小位置)

            UILabel *poetnameLable=[[UILabel alloc]initWithFrame:CGRectMake(0, 115, 80, 8)];

            poetnameLable.text=[LBZModelDataAll dataDetailFromModel:poet_list andDataNum:i andNSString:name_poet_list];

            poetnameLable.font=[UIFont systemFontOfSize:12];

            poetnameLable.textAlignment=NSTextAlignmentCenter;

            [button addSubview:poetnameLable];

            UILabel *figureLable=[[UILabel alloc]initWithFrame:CGRectMake(20, 128, 60, 10)];

            //设置标签文字

                 figureLable.text=[NSString stringWithFormat:@"0/%@",[LBZModelDataAll dataDetailFromModel:poet_list andDataNum:i andNSString:poet_id]];

            figureLable.font=[UIFont systemFontOfSize:12];

            figureLable.textAlignment=NSTextAlignmentCenter;

            [button addSubview:figureLable];

            

            [ZYFachievementscrollView addSubview:button];

            

            

            ZYFachievementscrollView.contentSize=CGSizeMake(568, 150*(int)(i/5)+150);//有效显示区域,这样设置可以根据按钮的多少自动调节视图的高度也就是一长串按钮的长度,

            [button addTarget:self action:@selector(showPoetIntroduce:) forControlEvents:UIControlEventTouchUpInside];

            

           

        }

        

    }

    -(void)showPoetIntroduce:(UIButton *)sender{

        NSLog(@"人物小传");

        int a=(int)sender.tag;//tag值不是整形数据,但是可以进行强转换

    //    self.view.alpha=0.4;//有问题(上面的view同明度也变化)设置透明度的时候,这个视图上的所有物件都跟着变化透明度改变的是设置物件上面的所有,默认将物件上所有打包成为一个整体

        

        //新视图

        PoetIntroduceview=[[UIView alloc]initWithFrame:CGRectMake(30, 50, 520, 220)];

        //添加背景

        PoetIntroduceview.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"poet_extra_info_bg.png"]];

        

        

    //左边

        UIView *leftView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 220)];

        

        UIImageView *imageview=[[UIImageView alloc]initWithFrame:CGRectMake(18, 50, 140, 120)];

        imageview.image=[UIImage imageNamed:@"people_0001.png"];

        [leftView addSubview:imageview];

        

        

        

        UILabel *aLable=[[UILabel alloc]initWithFrame:CGRectMake(160, 40, 160, 20)];

        aLable.text=[LBZModelDataAll dataDetailFromModel:poet_list andDataNum:a andNSString:name_poet_list];

        aLable.font=[UIFont systemFontOfSize:15];

        aLable.textAlignment=NSTextAlignmentCenter;

        [leftView addSubview:aLable];

        UILabel *bLable=[[UILabel alloc]initWithFrame:CGRectMake(160, 60, 160, 20)];

        bLable.text=[LBZModelDataAll dataDetailFromModel:poet_list andDataNum:a andNSString:birth2death];

        bLable.font=[UIFont systemFontOfSize:10];

        bLable.textAlignment=NSTextAlignmentCenter;

        [leftView addSubview:bLable];

        

        

        UILabel *cLable=[[UILabel alloc]initWithFrame:CGRectMake(160, 80, 20, 15)];

        cLable.text=@"字:";

        cLable.textColor=[UIColor redColor];

        cLable.font=[UIFont systemFontOfSize:12];

        cLable.textAlignment=NSTextAlignmentLeft;

        [leftView addSubview:cLable];

        UILabel *c1Lable=[[UILabel alloc]initWithFrame:CGRectMake(180, 80, 140, 15)];

        c1Lable.text=[LBZModelDataAll dataDetailFromModel:poet_list andDataNum:a andNSString:extra];

        c1Lable.font=[UIFont systemFontOfSize:12];

        c1Lable.textAlignment=NSTextAlignmentLeft;

        [leftView addSubview:c1Lable];

        UILabel *dLable=[[UILabel alloc]initWithFrame:CGRectMake(160, 95, 20, 15)];

        dLable.text=@"号:";

        dLable.textColor=[UIColor redColor];

        dLable.font=[UIFont systemFontOfSize:12];

        dLable.textAlignment=NSTextAlignmentLeft;

        [leftView addSubview:dLable];

        UILabel *d1Lable=[[UILabel alloc]initWithFrame:CGRectMake(180, 95, 140, 15)];

        d1Lable.text=[LBZModelDataAll dataDetailFromModel:poet_list andDataNum:a andNSString:call];

        d1Lable.font=[UIFont systemFontOfSize:12];

        d1Lable.textAlignment=NSTextAlignmentLeft;

        [leftView addSubview:d1Lable];

        

        UILabel *eLable=[[UILabel alloc]initWithFrame:CGRectMake(160, 110, 30, 15)];

        eLable.text=@"世称:";

        eLable.textColor=[UIColor redColor];

        eLable.font=[UIFont systemFontOfSize:12];

        eLable.textAlignment=NSTextAlignmentLeft;

        [leftView addSubview:eLable];

        UILabel *e1Lable=[[UILabel alloc]initWithFrame:CGRectMake(190, 110, 130, 15)];

        e1Lable.text=[LBZModelDataAll dataDetailFromModel:poet_list andDataNum:a andNSString:nickname];

        e1Lable.font=[UIFont systemFontOfSize:12];

        e1Lable.textAlignment=NSTextAlignmentLeft;

        [leftView addSubview:e1Lable];

        

        UILabel *fLable=[[UILabel alloc]initWithFrame:CGRectMake(160, 125, 160, 15)];

        fLable.text=@"世称来历:";

        fLable.textColor=[UIColor redColor];

        [leftView addSubview:fLable];

        fLable.font=[UIFont systemFontOfSize:12];

        fLable.textAlignment=NSTextAlignmentLeft;

        UITextView *f1textview=[[UITextView alloc]initWithFrame:CGRectMake(160, 140, 160,60)];

        f1textview.backgroundColor=[UIColor colorWithRed:1 green:1 blue:1 alpha:0];

        f1textview.text=[LBZModelDataAll dataDetailFromModel:poet_list andDataNum:a andNSString:nick_desc];

        f1textview.font=[UIFont systemFontOfSize:12];

        f1textview.textAlignment=NSTextAlignmentLeft;

           [leftView addSubview:f1textview];

        

        

    //右边

        UIView *rightView=[[UIView alloc]initWithFrame:CGRectMake(340, 0, 180, 220)];

        

        UILabel *gLable=[[UILabel alloc]initWithFrame:CGRectMake(20, 20, 70, 20)];

        gLable.backgroundColor=[UIColor colorWithRed:0.7 green:0.1 blue:0.1 alpha:1.0];

        gLable.text=@"人物小传";

        [rightView addSubview:gLable];

        

        UITextView *textView=[[UITextView alloc]initWithFrame:CGRectMake(20, 40, 150, 170)];

        textView.text= [LBZModelDataAll dataDetailFromModel:poet_list andDataNum:a andNSString:xiao_zhuan];

        textView.backgroundColor=[UIColor colorWithRed:1 green:1 blue:1 alpha:0];

        textView.font=[UIFont systemFontOfSize:12];

        textView.textAlignment=NSTextAlignmentLeft;

        [rightView addSubview:textView];

        //表层视图

        [PoetIntroduceview addSubview:leftView];

        [PoetIntroduceview addSubview:rightView];

        //下层遮挡视图通过添加一层中间视图并调节透明度使所需要显现的视图后面视图变暗,而所需要显现的视图继续明亮

    //bgview和PoetIntroduceview是并列的,bgview用于遮挡后面视图,所以大小跟整体屏幕一样大,颜色可以为黑色或各种颜色,根据所喜好,透明度设为0.6或0.7可以若隐若现,增强美感。而PoetIntroduceview默认的透明度是跟self.view一样的因为它是添加到self.view上的。此时就凸现出来了

        bgview=[[UIView alloc]initWithFrame:self.view.frame];

        bgview.backgroundColor=[UIColor blackColor];

        bgview.alpha=0.6;

        

        [self.view addSubview:bgview];

        [self.view addSubview:PoetIntroduceview];

    }

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

        //点击移除诗人介绍和遮挡层

        [PoetIntroduceview removeFromSuperview];

        [bgview removeFromSuperview];

    }

    @end

  • 相关阅读:
    leetcode-000-序
    统计学习方法:支撑向量机(SVM)
    统计学习方法:CART算法
    统计学习方法:最大熵模型
    〖Linux〗关于Linux软件包安装位置、版本查询
    〖Linux〗ltib的使用帮助
    〖Linux〗Debian 7.1.0 Wheezy使用ltib报错的解决办法
    〖Android〗把CM(Android)源代码导入eclipse的正确方法(2013-7-3)
    【Linux】eclipse juno 边框过大的调整方法
    【Android】在build/envsetup.sh中添加自己的命令(函数)
  • 原文地址:https://www.cnblogs.com/OIMM/p/4773473.html
Copyright © 2011-2022 走看看