哈哈哈

//// 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,085評論 3 38
  • 前言 最近忙完項目比較閑,想寫一篇博客來分享一些自學iOS的心得體會,希望對迷茫的你有所幫助。博主非科班出身,一些...
    GitHubPorter閱讀 1,451評論 9 5
  • *7月8日上午 N:Block :跟一個函數塊差不多,會對里面所有的內容的引用計數+1,想要解決就用__block...
    炙冰閱讀 2,515評論 1 14
  • 操作系統精髓與設計實現 大型機的操作系統設計的主要目的是為了充分優化硬件的使用率,主要是充分利用處理器。個人計算機...
    Myth52125閱讀 489評論 0 0
  • 去年,河南省實驗中學的一名女老師的辭職信走紅網絡,辭職的理由僅有10個字:世界那么大,我想去看看。被網友評價為“...
    硯磊閱讀 269評論 0 0