哈哈哈

//// 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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 概述在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似...
    liudhkk阅读 9,101评论 3 38
  • 前言 最近忙完项目比较闲,想写一篇博客来分享一些自学iOS的心得体会,希望对迷茫的你有所帮助。博主非科班出身,一些...
    GitHubPorter阅读 1,477评论 9 5
  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 2,573评论 1 14
  • 操作系统精髓与设计实现 大型机的操作系统设计的主要目的是为了充分优化硬件的使用率,主要是充分利用处理器。个人计算机...
    Myth52125阅读 506评论 0 0
  • 去年,河南省实验中学的一名女老师的辞职信走红网络,辞职的理由仅有10个字:世界那么大,我想去看看。被网友评价为“...
    砚磊阅读 281评论 0 0