滚动(隐藏视图)

#import “ViewController.h”
#import “YdViewController.h”
#import “CmViewController.h”
#import “RgViewController.h”
#import “WgViewController.h”
#import “YjsViewController.h”
#import “JzViewController.h”
#import “WzViewController.h”

#import “XLSlideSwitch.h”
@interface ViewController (){
UIButton *Btn;
UIView *SomeView;
}
@property (nonatomic , strong)XLSlideSwitch *ScrollView;
@end

@implementation ViewController

  • (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @“八维教育”;
    self.view.backgroundColor =[UIColor blueColor];

    NSArray *TitlesArr = @[@“移动通讯” , @“传媒” , @“软工” , @“网工” , @“云计算” , @“建筑”,@“网工”];
    NSArray *ControllersArr = @[@“YdViewController” , @“CmViewController” , @“RgViewController” , @“WgViewController” , @“YjsViewController” , @“JzViewController”,@“WzViewController”];
    NSMutableArray *ViewControllers = [[NSMutableArray alloc] init];
    for (int i = 0 ; i < TitlesArr.count; i ++) {
    //字符串创建控制器
    UIViewController *VC = [[NSClassFromString(ControllersArr[i])alloc] init];
    [ViewControllers addObject:VC];
    }
    //滚动视图
    _ScrollView = [[XLSlideSwitch alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 64) Titles:TitlesArr viewControllers:ViewControllers];
    _ScrollView.delegate = self;
    _ScrollView.itemNormalColor = [UIColor darkGrayColor];
    _ScrollView.itemSelectedColor = self.navigationController.navigationBar.tintColor;
    _ScrollView.customTitleSpacing = 30;
    _ScrollView.moreButton = [self moreButton];
    [_ScrollView showInViewController:self];

    //w点击隐藏 或 不隐藏View
    SomeView = [[UIView alloc]initWithFrame:CGRectMake(260, 105, 154, 200)];
    SomeView.backgroundColor = [UIColor orangeColor];
    SomeView.hidden=YES;
    NSArray *arr = @[@“确认添加”,@“删除添加”,@“关闭”];
    for (int i = 0; i UIButton btn1 = [[UIButton alloc]initWithFrame:CGRectMake(2, 5+ i60, 150, 60)];
    [btn1 setTitle:arr[i] forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(btn:) forControlEvents:UIControlEventTouchUpInside];
    btn1.tag = 100+i;
    btn1.backgroundColor = [UIColor redColor];
    [SomeView addSubview:btn1];
    }
    [self.view addSubview:SomeView];
    }

  • (UIButton *)moreButton{
    Btn = [[UIButton alloc] init];
    // [button setImage:[UIImage imageNamed:@“channelAdd”] forState:UIControlStateNormal];
    [Btn setTitle:@“➕” forState:UIControlStateNormal];
    [Btn setImageEdgeInsets:UIEdgeInsetsMake(8, 8, 8, 8)];
    [Btn addTarget:self action:@selector(BtnTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
    return Btn;
    }

  • (void)BtnTouchUpInside{
    NSLog(@“点击了添加按钮”);
    if (Btn.selected == YES) {
    // SomeView.hidden = YES;
    Btn.selected = NO;
    SomeView.hidden = YES;
    }else{
    Btn.selected = YES;
    SomeView.hidden = NO;
    }
    }

  • (void)btn:(UIButton *)button{
    if (button.tag == 100) {
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@“确认添加” message:@“操作已完成” delegate:self cancelButtonTitle:@“确认” otherButtonTitles:nil, nil];
    [alert show];
    }else if (button.tag == 101){
    NSLog(@“222”);
    }else{
    NSLog(@“333”);
    }
    }
    @end

你可能感兴趣的:(隐藏视图)