哈哈哈

作者: 本泽马 | 来源:发表于2018-01-19 13:43 被阅读0次

//// ViewController.m// 实训一练习//// Created by 员非凡 on 2018/1/17.// Copyright © 2018年 yff. All rights reserved.//#import "ViewController.h"#import "SGPagingView.h"#import "oneViewController.h"#import "twoViewController.h"#import "threeViewController.h"#import "fourViewController.h"#import "fiveViewController.h"#import "sixViewController.h"#import "caidanViewController.h"@interface ViewController ()@property (nonatomic, strong) SGPageTitleView *pageTitleView;

@property (nonatomic, strong) SGPageContentView *pageContentView;

@property (nonatomic, assign) BOOL isPushNextVC;

@property (nonatomic,strong) UIButton *jaihaobutton;

@property (nonatomic,strong) caidanViewController *itemPopVC;

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    self.view.backgroundColor = [UIColor whiteColor];

    self.jaihaobutton = [[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width-40, 60, 40, 40)];

    //self.jaihaobutton.backgroundColor = [UIColor redColor];

    [self.jaihaobutton setTitle:@"+" forState:UIControlStateNormal];

    [self.jaihaobutton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];

    [self.jaihaobutton addTarget:self action:@selector(jiahao) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:self.jaihaobutton];

    [self setupNavigationBar];

}

-(void)jiahao{

    //初始化 VC

    self.itemPopVC = [[caidanViewController alloc] init];

    //设置 VC 弹出方式

    self.itemPopVC.modalPresentationStyle = UIModalPresentationPopover;

    //设置依附的按钮

    self.itemPopVC.popoverPresentationController.sourceView = self.jaihaobutton;

    //可以指示小箭头颜色

    self.itemPopVC.popoverPresentationController.backgroundColor = [UIColor grayColor];

    //箭头方向

    self.itemPopVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;

    // 指定箭头所指区域的矩形框范围(位置和尺寸),以sourceView的左上角为坐标原点

    // 这个可以 通过 Point 或  Size 调试位置

    self.itemPopVC.popoverPresentationController.sourceRect = self.jaihaobutton.bounds;

    //代理

    self.itemPopVC.popoverPresentationController.delegate = self;

    [self presentViewController:self.itemPopVC animated:YES completion:nil];

    //content尺寸

    //self.itemPopVC.preferredContentSize = CGSizeMake(400, 400);

}

- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {

    return UIModalPresentationNone;

}

- (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController{

    return YES;  //点击蒙版popover消失, 默认YES

}

- (void)setupNavigationBar {

    NSArray *titleArr = [@[@"移动通讯", @"传媒", @"网工", @"软工", @"云计算", @"建筑", ]mutableCopy];

    SGPageTitleViewConfigure *configure = [SGPageTitleViewConfigure pageTitleViewConfigure];

    /// pageTitleView

    // 这里的 - 10 是为了让 SGPageTitleView 超出父视图,给用户一种效果体验

    self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, 60, self.view.frame.size.width-40    , 44) delegate:self titleNames:titleArr configure:configure];

    //_pageTitleView.backgroundColor = [UIColor yellowColor];

    [self.view addSubview:_pageTitleView];

    oneViewController *oneVC = [[oneViewController alloc] init];

    twoViewController *twoVC = [[twoViewController alloc] init];

    threeViewController *threeVC = [[threeViewController alloc] init];

    fourViewController *fourVC = [[fourViewController alloc] init];

    fiveViewController *fiveVC = [[fiveViewController alloc] init];

    sixViewController *sixVC = [[sixViewController alloc] init];

    NSArray *childArr = @[oneVC, twoVC, threeVC, fourVC, fiveVC, sixVC];

    /// pageContentView

    CGFloat contentViewHeight = self.view.frame.size.height - 104;

    self.pageContentView = [[SGPageContentView alloc] initWithFrame:CGRectMake(0, 104, self.view.frame.size.width, contentViewHeight) parentVC:self childVCs:childArr];

    _pageContentView.delegatePageContentView = self;

    [self.view addSubview:_pageContentView];

}

- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {

    [self.pageContentView setPageCententViewCurrentIndex:selectedIndex];

}

- (void)pageContentView:(SGPageContentView *)pageContentView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex {

    [self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];

}

@end

//// caidanViewController.m// 实训一练习//// Created by 员非凡 on 2018/1/17.// Copyright © 2018年 yff. All rights reserved.//#import "caidanViewController.h"@interface caidanViewController (){

    NSMutableArray *_addArray;

}

@property (nonatomic,strong)UITableView *tableView;

@end

@implementation caidanViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColor whiteColor];

    [self setupView];

}

#pragma mark 创建 tableView

- (void)setupView {

    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame];

  self. tableView.dataSource = self;

    self.tableView.delegate = self;

    self.tableView.scrollEnabled = NO;

    self.tableView.backgroundColor = [UIColor grayColor];

    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];

    [self.view addSubview:self.tableView];

    //    [self.tableView setSeparatorColor:[UIColor whiteColor]];

    _addArray = [NSMutableArray arrayWithObjects:@"确认添加",@"删除添加",@"关闭", nil];

}

#pragma mark tabelView 协议方法

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return _addArray.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

    cell.backgroundColor = [UIColor grayColor];

    //    cell.textLabel.textAlignment = NSTextAlignmentCenter;

    cell.textLabel.text = _addArray[indexPath.row];

    cell.textLabel.textColor = [UIColor whiteColor];

    return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSLog(@"%zd",indexPath.row);

    // 初始化提示框控制器

    UIAlertController *Alc = [UIAlertController alertControllerWithTitle:@"确认添加" message:@"操作已完成" preferredStyle:UIAlertControllerStyleAlert];

    // 初始化  提示框上的按钮

    UIAlertAction *AcOne  = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        [self.tableView reloadData];

    }];

    // 将按钮添加到控制器上

    [Alc addAction:AcOne];

    // 展示提示框

    [self presentViewController:Alc animated:YES completion:nil];

}

- (CGSize)preferredContentSize {

    if (self.presentingViewController && self.tableView != nil) {

        CGSize tempSize = self.presentingViewController.view.bounds.size;

        tempSize.width = 150;

        //返回一个完美适应tableView的大小的 size; sizeThatFits 返回的是最合适的尺寸, 但不会改变控件的大小

        CGSize size = [self.tableView sizeThatFits:tempSize];

        return size;

    }else{

        return [self preferredContentSize];

    }

}

@end

//// caidanViewController.m// 实训一练习//// Created by 员非凡 on 2018/1/17.// Copyright © 2018年 yff. All rights reserved.//#import "caidanViewController.h"@interface caidanViewController (){

    NSMutableArray *_addArray;

}

@property (nonatomic,strong)UITableView *tableView;

@end

@implementation caidanViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColor whiteColor];

    [self setupView];

}

#pragma mark 创建 tableView

- (void)setupView {

    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame];

  self. tableView.dataSource = self;

    self.tableView.delegate = self;

    self.tableView.scrollEnabled = NO;

    self.tableView.backgroundColor = [UIColor grayColor];

    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];

    [self.view addSubview:self.tableView];

    //    [self.tableView setSeparatorColor:[UIColor whiteColor]];

    _addArray = [NSMutableArray arrayWithObjects:@"确认添加",@"删除添加",@"关闭", nil];

}

#pragma mark tabelView 协议方法

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return _addArray.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

    cell.backgroundColor = [UIColor grayColor];

    //    cell.textLabel.textAlignment = NSTextAlignmentCenter;

    cell.textLabel.text = _addArray[indexPath.row];

    cell.textLabel.textColor = [UIColor whiteColor];

    return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSLog(@"%zd",indexPath.row);

    // 初始化提示框控制器

    UIAlertController *Alc = [UIAlertController alertControllerWithTitle:@"确认添加" message:@"操作已完成" preferredStyle:UIAlertControllerStyleAlert];

    // 初始化  提示框上的按钮

    UIAlertAction *AcOne  = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        [self.tableView reloadData];

    }];

    // 将按钮添加到控制器上

    [Alc addAction:AcOne];

    // 展示提示框

    [self presentViewController:Alc animated:YES completion:nil];

}

- (CGSize)preferredContentSize {

    if (self.presentingViewController && self.tableView != nil) {

        CGSize tempSize = self.presentingViewController.view.bounds.size;

        tempSize.width = 150;

        //返回一个完美适应tableView的大小的 size; sizeThatFits 返回的是最合适的尺寸, 但不会改变控件的大小

        CGSize size = [self.tableView sizeThatFits:tempSize];

        return size;

    }else{

        return [self preferredContentSize];

    }

}

@end

网友评论

      本文标题:哈哈哈

      本文链接:https://www.haomeiwen.com/subject/vjmooxtx.html