├── README.md ├── 两个滚动视图做界面.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── leiyu.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── leiyu.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── xcschememanagement.plist │ └── 两个滚动视图做界面.xcscheme ├── 两个滚动视图做界面 ├── 1.jpg ├── 10.jpg ├── 11.jpg ├── 12.png ├── 2.jpg ├── 3.jpg ├── 4.jpg ├── 5.jpg ├── 6.png ├── 7.jpg ├── 8.png ├── 9.jpg ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── ButtonsCell.h ├── ButtonsCell.m ├── ButtonsCell.xib ├── ButtonsTableViewController.h ├── ButtonsTableViewController.m ├── ButtonsTableViewController.xib ├── ButtonsView.h ├── ButtonsView.m ├── ButtonsView_CreateString.h ├── DataModel.h ├── DataModel.m ├── ImageCell.h ├── ImageCell.m ├── ImageCell.xib ├── Info.plist ├── MainViewController.h ├── MainViewController.m ├── MyCell.h ├── MyCell.m ├── MyCell.xib ├── MyTableViewController.h ├── MyTableViewController.m ├── MyTableViewController.xib ├── TRButton.h ├── TRButton.m ├── TitleView.h ├── TitleView.m ├── UIColor+SelfColor.h ├── UIColor+SelfColor.m └── main.m ├── 两个滚动视图做界面Tests ├── Info.plist └── _________Tests.m ├── 两个滚动视图做界面UITests ├── Info.plist └── _________UITests.m └── 两个滚动视图实现腾讯新闻的效果 └── 两个滚动视图做界面 ├── 两个滚动视图做界面.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── leiyu.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── leiyu.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── xcschememanagement.plist │ └── 两个滚动视图做界面.xcscheme ├── 两个滚动视图做界面 ├── 1.jpg ├── 10.jpg ├── 11.jpg ├── 12.png ├── 2.jpg ├── 3.jpg ├── 4.jpg ├── 5.jpg ├── 6.png ├── 7.jpg ├── 8.png ├── 9.jpg ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── ButtonsCell.h ├── ButtonsCell.m ├── ButtonsCell.xib ├── ButtonsTableViewController.h ├── ButtonsTableViewController.m ├── ButtonsTableViewController.xib ├── ButtonsView.h ├── ButtonsView.m ├── ButtonsView_CreateString.h ├── DataModel.h ├── DataModel.m ├── ImageCell.h ├── ImageCell.m ├── ImageCell.xib ├── Info.plist ├── MainViewController.h ├── MainViewController.m ├── MyCell.h ├── MyCell.m ├── MyCell.xib ├── MyTableViewController.h ├── MyTableViewController.m ├── MyTableViewController.xib ├── TRButton.h ├── TRButton.m ├── TitleView.h ├── TitleView.m ├── UIColor+SelfColor.h ├── UIColor+SelfColor.m └── main.m ├── 两个滚动视图做界面Tests ├── Info.plist └── _________Tests.m └── 两个滚动视图做界面UITests ├── Info.plist └── _________UITests.m /两个滚动视图做界面.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /两个滚动视图做界面.xcodeproj/project.xcworkspace/xcuserdata/leiyu.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图做界面.xcodeproj/project.xcworkspace/xcuserdata/leiyu.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /两个滚动视图做界面.xcodeproj/xcuserdata/leiyu.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /两个滚动视图做界面.xcodeproj/xcuserdata/leiyu.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 两个滚动视图做界面.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | E64DAD9A1D20D10800A47890 16 | 17 | primary 18 | 19 | 20 | E64DADB31D20D10800A47890 21 | 22 | primary 23 | 24 | 25 | E64DADBE1D20D10800A47890 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /两个滚动视图做界面.xcodeproj/xcuserdata/leiyu.xcuserdatad/xcschemes/两个滚动视图做界面.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 89 | 90 | 91 | 92 | 98 | 100 | 106 | 107 | 108 | 109 | 111 | 112 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /两个滚动视图做界面/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图做界面/1.jpg -------------------------------------------------------------------------------- /两个滚动视图做界面/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图做界面/10.jpg -------------------------------------------------------------------------------- /两个滚动视图做界面/11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图做界面/11.jpg -------------------------------------------------------------------------------- /两个滚动视图做界面/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图做界面/12.png -------------------------------------------------------------------------------- /两个滚动视图做界面/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图做界面/2.jpg -------------------------------------------------------------------------------- /两个滚动视图做界面/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图做界面/3.jpg -------------------------------------------------------------------------------- /两个滚动视图做界面/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图做界面/4.jpg -------------------------------------------------------------------------------- /两个滚动视图做界面/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图做界面/5.jpg -------------------------------------------------------------------------------- /两个滚动视图做界面/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图做界面/6.png -------------------------------------------------------------------------------- /两个滚动视图做界面/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图做界面/7.jpg -------------------------------------------------------------------------------- /两个滚动视图做界面/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图做界面/8.png -------------------------------------------------------------------------------- /两个滚动视图做界面/9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图做界面/9.jpg -------------------------------------------------------------------------------- /两个滚动视图做界面/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /两个滚动视图做界面/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "UIColor+SelfColor.h" 11 | 12 | @interface AppDelegate () 13 | 14 | @end 15 | 16 | @implementation AppDelegate 17 | 18 | 19 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 20 | { 21 | //建立两个新闻数组 并永久储存 22 | NSUserDefaults* newsData = [NSUserDefaults standardUserDefaults]; 23 | NSArray* array = @[@"佛学",@"军事",@"电竞",@"电视剧",@"纪录片",@"财经",@"娱乐",@"要闻",@"体育",@"汽车",@"图片",@"科技",@"社会"]; 24 | NSArray* array1 = @[@"时尚",@"游戏",@"房产",@"数码",@"股票",@"国际",@"教育",@"读科学"]; 25 | NSArray* array2 = @[@"重庆",@"四川",@"上海",@"陕西",@"山东",@"浙江",@"湖北",@"河南",@"湖南",@"福建",@"江苏",@"北京",@"广州",@"深圳"]; 26 | [newsData setObject:array forKey:@"testArray"]; 27 | [newsData setObject:array1 forKey:@"testArray1"]; 28 | [newsData setObject:array2 forKey:@"testArray2"]; 29 | [[UINavigationBar appearance]setBarTintColor:[UIColor whiteColor]]; 30 | [[UINavigationBar appearance]setTintColor:[UIColor getColor:@"EF7000"]]; 31 | [[UINavigationBar appearance]setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:17],NSForegroundColorAttributeName:[UIColor blackColor]}]; 32 | return YES; 33 | } 34 | 35 | - (void)applicationWillResignActive:(UIApplication *)application { 36 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 37 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 38 | } 39 | 40 | - (void)applicationDidEnterBackground:(UIApplication *)application { 41 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 42 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 43 | } 44 | 45 | - (void)applicationWillEnterForeground:(UIApplication *)application { 46 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 47 | } 48 | 49 | - (void)applicationDidBecomeActive:(UIApplication *)application { 50 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 51 | } 52 | 53 | - (void)applicationWillTerminate:(UIApplication *)application { 54 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /两个滚动视图做界面/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /两个滚动视图做界面/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /两个滚动视图做界面/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /两个滚动视图做界面/ButtonsCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonsCell.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/28. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ButtonsCell : UITableViewCell 12 | @property (strong, nonatomic) IBOutlet UILabel *myLabel; 13 | @property (strong, nonatomic) IBOutlet UIButton *myButton; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /两个滚动视图做界面/ButtonsCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonsCell.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/28. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "ButtonsCell.h" 10 | 11 | @implementation ButtonsCell 12 | 13 | - (void)awakeFromNib { 14 | [super awakeFromNib]; 15 | // Initialization code 16 | } 17 | 18 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 19 | [super setSelected:selected animated:animated]; 20 | 21 | // Configure the view for the selected state 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /两个滚动视图做界面/ButtonsCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 28 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /两个滚动视图做界面/ButtonsTableViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonsTableViewController.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/28. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ButtonsTableViewController : UITableViewController 12 | 13 | @property (nonatomic, strong) NSArray* buttonTitles; 14 | @property (nonatomic, unsafe_unretained) NSInteger buttonIndex; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /两个滚动视图做界面/ButtonsTableViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonsTableViewController.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/28. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "ButtonsTableViewController.h" 10 | #import "ButtonsCell.h" 11 | #import "ButtonsView.h" 12 | #import "DataModel.h" 13 | #import "TRButton.h" 14 | 15 | #define WIDTH [UIScreen mainScreen].bounds.size.width 16 | #define KONGWIDTH (WIDTH - 4*60)/5 17 | 18 | @interface ButtonsTableViewController () 19 | @property (nonatomic, strong) NSArray* testArray1; 20 | @property (nonatomic, strong) NSArray* testArray2; 21 | @property (nonatomic, unsafe_unretained) NSInteger isLeft; 22 | @property (nonatomic, strong) UIView* view1; 23 | @property (nonatomic, strong) UIView* view2; 24 | @property (nonatomic, strong) ButtonsView* buttonsView; 25 | 26 | @property (nonatomic, strong) NSString* myTitle; 27 | 28 | @end 29 | 30 | @implementation ButtonsTableViewController 31 | 32 | - (ButtonsView*)buttonsView 33 | { 34 | if (!_buttonsView) 35 | { 36 | _buttonsView = [[ButtonsView alloc]init]; 37 | } 38 | return _buttonsView; 39 | } 40 | - (NSArray*)testArray1 41 | { 42 | if (!_testArray1) 43 | { 44 | NSUserDefaults* newsData = [NSUserDefaults standardUserDefaults]; 45 | _testArray1 = [newsData objectForKey:@"testArray1"]; 46 | } 47 | return _testArray1; 48 | } 49 | - (NSArray*)testArray2 50 | { 51 | if (!_testArray2) 52 | { 53 | NSUserDefaults* newsData = [NSUserDefaults standardUserDefaults]; 54 | _testArray2 = [newsData objectForKey:@"testArray2"]; 55 | } 56 | return _testArray2; 57 | } 58 | 59 | - (void)viewDidLoad 60 | { 61 | [super viewDidLoad]; 62 | self.title = @"频道定制"; 63 | self.myTitle = [self getTitle]; 64 | [self createHeaderView]; 65 | self.tableView.tableHeaderView = self.buttonsView; 66 | self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action:@selector(goBack)]; 67 | [self.tableView registerNib:[UINib nibWithNibName:@"ButtonsCell" bundle:nil] forCellReuseIdentifier:@"cell"]; 68 | [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(buttonChange:) name:@"buttonChange" object:nil]; 69 | [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(buttonChange1:) name:@"buttonChange1" object:nil]; 70 | [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(buttonChange5:) name:@"buttonChange5" object:nil]; 71 | } 72 | 73 | - (void)viewDidAppear:(BOOL)animated 74 | { 75 | [super viewDidAppear:animated]; 76 | self.isLeft = 0; 77 | 78 | } 79 | //创建头视图(规矩排列的按钮组) 80 | - (void)createHeaderView 81 | { 82 | self.buttonsView.buttonTitles = self.buttonTitles; 83 | self.buttonsView.index = self.isLeft; 84 | self.buttonsView.buttonTitles1 = @[@"推荐频道",@"地方频道"]; 85 | [self.buttonsView createButtons]; 86 | } 87 | //点击表视图头部的按钮 88 | - (void)buttonChange:(NSNotification*)notification 89 | { 90 | NSLog(@"点击表视图头部的按钮"); 91 | NSUserDefaults* newsData = [NSUserDefaults standardUserDefaults]; 92 | TRButton* button = (TRButton*)notification.userInfo[@"button"]; 93 | if ([[DataModel getNewsArray][button.currentTitle][@"type"] isEqualToString:@"推荐"]) 94 | { 95 | NSMutableArray* array = [NSMutableArray arrayWithArray:self.testArray1]; 96 | [array insertObject:button.currentTitle atIndex:0]; 97 | self.testArray1 = [array copy]; 98 | [newsData setObject:self.testArray1 forKey:@"testArray1"]; 99 | self.isLeft = 0; 100 | } 101 | else 102 | { 103 | NSMutableArray* array = [NSMutableArray arrayWithArray:self.testArray2]; 104 | [array insertObject:button.currentTitle atIndex:0]; 105 | self.testArray2 = [array copy]; 106 | [newsData setObject:self.testArray2 forKey:@"testArray2"]; 107 | self.isLeft = 1; 108 | } 109 | self.buttonsView.index = self.isLeft; 110 | [self.buttonsView removeAllButtons]; 111 | [self.buttonsView createChannelButton]; 112 | self.buttonTitles = notification.userInfo[@"buttonArray"]; 113 | self.tableView.tableHeaderView = self.buttonsView; 114 | [self.tableView reloadData]; 115 | } 116 | 117 | //改变按钮位置 重新排列数组 得到新的数组 118 | - (void)buttonChange5:(NSNotification*)notification 119 | { 120 | NSLog(@"改变按钮位置 重新排列数组 得到新的数组"); 121 | self.buttonTitles = notification.userInfo[@"buttonArray"]; 122 | self.tableView.tableHeaderView = self.buttonsView; 123 | [self.tableView reloadData]; 124 | } 125 | //点击频道 126 | - (void)buttonChange1:(NSNotification*)notification 127 | { 128 | self.isLeft = [notification.userInfo[@"buttonTag"] integerValue]; 129 | NSLog(@"点击了哪个频道 %ld",(long)self.isLeft); 130 | self.tableView.tableHeaderView = self.buttonsView; 131 | [self.tableView reloadData]; 132 | } 133 | - (void)goBack 134 | { 135 | NSUserDefaults* newsData = [NSUserDefaults standardUserDefaults]; 136 | [newsData setObject:self.buttonTitles forKey:@"testArray"]; 137 | [[NSNotificationCenter defaultCenter]postNotificationName:@"ChangeArray" object:self userInfo:@{@"array":self.buttonTitles,@"index":[NSString stringWithFormat:@"%ld",(long)[self getIndex]]}]; 138 | [self dismissViewControllerAnimated:YES completion:nil]; 139 | } 140 | //添加频道 141 | - (void)addData:(UIButton*)sender 142 | { 143 | [self.buttonsView removeAllButtons]; 144 | [self.buttonsView removeAllButtons1]; 145 | self.buttonTitles = self.buttonsView.buttonTitles; 146 | ButtonsCell *cell = (ButtonsCell*)[[sender superview]superview]; 147 | NSMutableArray* array = [NSMutableArray arrayWithArray:self.buttonTitles]; 148 | [array addObject:cell.myLabel.text]; 149 | self.buttonTitles = [array copy]; 150 | [self createHeaderView]; 151 | NSUserDefaults* newsData = [NSUserDefaults standardUserDefaults]; 152 | //删除行 153 | if (self.isLeft == 0) 154 | { 155 | NSMutableArray* array = [NSMutableArray arrayWithArray:self.testArray1]; 156 | [array removeObject:cell.myLabel.text]; 157 | self.testArray1 = [array copy]; 158 | [newsData setObject:self.testArray1 forKey:@"testArray1"]; 159 | } 160 | else 161 | { 162 | NSMutableArray* array = [NSMutableArray arrayWithArray:self.testArray2]; 163 | [array removeObject:cell.myLabel.text]; 164 | self.testArray2 = [array copy]; 165 | [newsData setObject:self.testArray2 forKey:@"testArray2"]; 166 | } 167 | dispatch_async(dispatch_get_main_queue(), ^{ 168 | self.tableView.tableHeaderView = self.buttonsView; 169 | [self.tableView reloadData]; 170 | }); 171 | } 172 | //刚加载完成的时候得到 上个页面的下标对应的title 173 | - (NSString*)getTitle 174 | { 175 | NSString* title = self.buttonTitles[self.buttonIndex]; 176 | return title; 177 | } 178 | //根据按钮的文字 获得在新数组里面的位置 179 | - (NSInteger)getIndex 180 | { 181 | if ([self.buttonTitles containsObject:self.myTitle]) 182 | { 183 | NSInteger index = [self.buttonTitles indexOfObject:self.myTitle]; 184 | return index; 185 | } 186 | else 187 | { 188 | return 0; 189 | } 190 | } 191 | #pragma mark - Table view data source 192 | 193 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 194 | { 195 | return 1; 196 | } 197 | 198 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 199 | { 200 | return self.isLeft == 0 ? self.testArray1.count : self.testArray2.count; 201 | } 202 | 203 | - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 204 | { 205 | return 1.0; 206 | } 207 | 208 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 209 | { 210 | ButtonsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath]; 211 | [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 212 | if (self.isLeft == 0) 213 | { 214 | cell.myLabel.text = self.testArray1[indexPath.row]; 215 | } 216 | else 217 | { 218 | cell.myLabel.text = self.testArray2[indexPath.row]; 219 | } 220 | [cell.myButton addTarget:self action:@selector(addData:) forControlEvents:UIControlEventTouchUpInside]; 221 | return cell; 222 | } 223 | 224 | 225 | @end 226 | -------------------------------------------------------------------------------- /两个滚动视图做界面/ButtonsTableViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /两个滚动视图做界面/ButtonsView.h: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonsView.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/28. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ButtonsView : UIView 12 | 13 | @property (nonatomic, strong) NSArray* buttonTitles; 14 | @property (nonatomic, strong) NSArray* buttonTitles1; 15 | @property (nonatomic, strong) NSMutableArray* allButtons; 16 | @property (nonatomic, strong) NSMutableArray* allButtons1; 17 | @property (nonatomic, strong) NSMutableArray* views; 18 | //一个判断是哪个按钮被按下的判断值 19 | @property (nonatomic, unsafe_unretained) NSInteger index; 20 | 21 | @property (nonatomic, strong) UIButton* moveButton; 22 | 23 | - (void)removeAllButtons; 24 | - (void)createButtons; 25 | - (void)removeAllButtons1; 26 | - (void)createChannelButton; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /两个滚动视图做界面/ButtonsView.m: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonsView.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/28. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "ButtonsView.h" 10 | #import "TRButton.h" 11 | #import "ButtonsView_CreateString.h" 12 | 13 | #define WIDTH [UIScreen mainScreen].bounds.size.width 14 | #define KONGWIDTH (WIDTH - 4*60)/5 15 | 16 | @interface ButtonsView () 17 | 18 | @end 19 | @implementation ButtonsView 20 | - (UILabel*)leftLabel 21 | { 22 | if (!_leftLabel) 23 | { 24 | _leftLabel = [[UILabel alloc]initWithFrame:CGRectMake(KONGWIDTH, 20, 100, 20)]; 25 | _leftLabel.text = @"已选频道"; 26 | _leftLabel.textAlignment = NSTextAlignmentLeft; 27 | _leftLabel.font = [UIFont systemFontOfSize:14]; 28 | _leftLabel.textColor = [UIColor colorWithRed:220.0/255.0 green:220.0/255.0 blue:220.0/255.0 alpha:1.0]; 29 | } 30 | return _leftLabel; 31 | } 32 | - (UILabel*)titleLabel 33 | { 34 | if (!_titleLabel) 35 | { 36 | _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH -150 - KONGWIDTH, 20, 150, 20)]; 37 | _titleLabel.text = @"按住拖动调整排序"; 38 | _titleLabel.textAlignment = NSTextAlignmentRight; 39 | _titleLabel.font = [UIFont systemFontOfSize:14]; 40 | _titleLabel.textColor = [UIColor colorWithRed:220.0/255.0 green:220.0/255.0 blue:220.0/255.0 alpha:1.0]; 41 | } 42 | return _titleLabel; 43 | } 44 | - (UIButton*)button1 45 | { 46 | if (!_button1) 47 | { 48 | _button1 = [[UIButton alloc]init]; 49 | _button1.tag = 0; 50 | [_button1 setTitle:self.buttonTitles1[0] forState:UIControlStateNormal]; 51 | [_button1 setBackgroundColor:[UIColor whiteColor]]; 52 | self.view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 28, 80, 2)]; 53 | 54 | self.view1.tag = 0; 55 | self.view1.backgroundColor = [UIColor orangeColor]; 56 | [self.views addObject:self.view1]; 57 | [self.allButtons1 addObject:_button1]; 58 | [_button1 addSubview:self.view1]; 59 | [_button1 addTarget:self action:@selector(showLeftData:) forControlEvents:UIControlEventTouchUpInside]; 60 | } 61 | return _button1; 62 | } 63 | - (UIButton*)button2 64 | { 65 | if (!_button2) 66 | { 67 | _button2 = [[UIButton alloc]init]; 68 | _button2.tag = 1; 69 | [_button2 setTitle:self.buttonTitles1[1] forState:UIControlStateNormal]; 70 | [_button2 setBackgroundColor:[UIColor whiteColor]]; 71 | self.view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 28, 80, 2)]; 72 | self.view2.tag = 1; 73 | self.view2.backgroundColor = [UIColor orangeColor]; 74 | [self.views addObject:self.view2]; 75 | [self.allButtons1 addObject:_button2]; 76 | [_button2 addSubview:self.view2]; 77 | [_button2 addTarget:self action:@selector(showLeftData:) forControlEvents:UIControlEventTouchUpInside]; 78 | } 79 | return _button2; 80 | } 81 | - (NSMutableArray*)allButtons 82 | { 83 | if (!_allButtons) 84 | { 85 | _allButtons = [NSMutableArray array]; 86 | } 87 | return _allButtons; 88 | } 89 | - (NSMutableArray*)allButtons1 90 | { 91 | if (!_allButtons1) 92 | { 93 | _allButtons1 = [NSMutableArray array]; 94 | } 95 | return _allButtons1; 96 | } 97 | - (NSMutableArray*)views 98 | { 99 | if (!_views) 100 | { 101 | _views = [NSMutableArray array]; 102 | } 103 | return _views; 104 | } 105 | - (id)init 106 | { 107 | if (self = [super init]) 108 | { 109 | self.backgroundColor = [UIColor whiteColor]; 110 | } 111 | return self; 112 | } 113 | 114 | - (void)createButtons 115 | { 116 | [self addSubview:self.leftLabel]; 117 | [self addSubview:self.titleLabel]; 118 | for (int i = 0; i < self.buttonTitles.count; i++) 119 | { 120 | //代表第几行 121 | NSInteger n = (NSInteger)i/4; 122 | //代表第几列 123 | NSInteger l = (NSInteger)i%4; 124 | TRButton* button=[TRButton buttonWithType:UIButtonTypeCustom]; 125 | button.delegate=self; 126 | button.tag = i; 127 | button.userInteractionEnabled = YES; 128 | button.frame = CGRectMake(((KONGWIDTH + 60) * l) + KONGWIDTH, (n * (KONGWIDTH + 30)) + 20 + 40, 60, 30); 129 | [button setTitle:self.buttonTitles[i] forState:UIControlStateNormal]; 130 | [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 131 | button.layer.borderWidth = 0.3; 132 | button.layer.borderColor = [UIColor colorWithRed:200.0/255.0 green:200.0/255.0 blue:200.0/255.0 alpha:1.0].CGColor; 133 | button.layer.cornerRadius = 3.0; 134 | button.layer.masksToBounds = YES; 135 | [button setBackgroundColor:[UIColor whiteColor]]; 136 | [self.allButtons addObject:button]; 137 | button.btnArray = self.allButtons; 138 | [self addSubview:button]; 139 | CGFloat height = button.frame.origin.y; 140 | CGFloat viewHeight = height + 50 + 30 + 40; 141 | self.frame = CGRectMake(0, 0, WIDTH, viewHeight); 142 | } 143 | [self createChannelButton]; 144 | } 145 | 146 | - (void)createChannelButton 147 | { 148 | self.button1.frame = CGRectMake((((WIDTH - 2*80)/3) + 80) * 0 + ((WIDTH - 2*80)/3), self.frame.size.height - 30, 80, 30); 149 | self.button2.frame = CGRectMake((((WIDTH - 2*80)/3) + 80) * 1 + ((WIDTH - 2*80)/3), self.frame.size.height - 30, 80, 30); 150 | if (self.index == 0) 151 | { 152 | [self.button1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; 153 | [self.button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 154 | self.view2.hidden = YES; 155 | self.view1.hidden = NO; 156 | } 157 | else 158 | { 159 | [self.button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 160 | [self.button2 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; 161 | self.view2.hidden = NO; 162 | self.view1.hidden = YES; 163 | } 164 | [self addSubview:self.button1]; 165 | [self addSubview:self.button2]; 166 | } 167 | //推荐频道和地方频道 168 | - (void)showLeftData:(UIButton*)sender 169 | { 170 | for (UIView* view in self.views) 171 | { 172 | if (view.tag == sender.tag) 173 | { 174 | view.hidden = NO; 175 | } 176 | else 177 | { 178 | view.hidden = YES; 179 | } 180 | } 181 | for (UIButton* button in self.allButtons1) 182 | { 183 | if (button.tag == sender.tag) 184 | { 185 | [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; 186 | } 187 | else 188 | { 189 | [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 190 | } 191 | } 192 | [[NSNotificationCenter defaultCenter]postNotificationName:@"buttonChange1" object:self userInfo:@{@"buttonTag":[NSString stringWithFormat:@"%ld",(long)sender.tag]}]; 193 | } 194 | 195 | - (void)removeAllButtons1 196 | { 197 | for (TRButton* button in self.allButtons) 198 | { 199 | [button removeFromSuperview]; 200 | } 201 | [self.allButtons removeAllObjects]; 202 | } 203 | - (void)removeAllButtons 204 | { 205 | for (UIButton* button in self.allButtons1) 206 | { 207 | [button removeFromSuperview]; 208 | } 209 | [self.allButtons1 removeAllObjects]; 210 | } 211 | - (void)dragButton1:(TRButton *)button buttons:(NSArray *)buttons 212 | { 213 | //点击哪个button 删除button 214 | NSMutableArray* array = [NSMutableArray arrayWithArray:self.buttonTitles]; 215 | [array removeObject:button.currentTitle]; 216 | self.buttonTitles = [array copy]; 217 | for (TRButton* button in self.allButtons) 218 | { 219 | CGFloat height = button.frame.origin.y; 220 | CGFloat viewHeight = height + 50 + 30 + 40; 221 | self.frame = CGRectMake(0, 0, WIDTH, viewHeight); 222 | } 223 | [[NSNotificationCenter defaultCenter]postNotificationName:@"buttonChange" object:self userInfo:@{@"button":button,@"buttonArray":self.buttonTitles}]; 224 | } 225 | //得到变化后的按钮数组 226 | - (void)dragButton:(TRButton *)button buttons:(NSArray *)buttons 227 | { 228 | // self.allButtons = [NSMutableArray arrayWithArray:buttons]; 229 | NSLog(@"buttons = %@",buttons); 230 | NSString* currentTitle=button.currentTitle; 231 | NSLog(@"%@位置发生了改变,counts=%lu",currentTitle,(unsigned long)button.tag); 232 | NSMutableArray* array = [NSMutableArray arrayWithArray:self.buttonTitles]; 233 | if ([buttons containsObject:button]) 234 | { 235 | NSInteger index = [buttons indexOfObject:button]; 236 | [array removeObjectAtIndex:button.tag]; 237 | [array insertObject:currentTitle atIndex:index]; 238 | self.buttonTitles = [array copy]; 239 | NSLog(@"index = %ld",(long)index); 240 | } 241 | [[NSNotificationCenter defaultCenter]postNotificationName:@"buttonChange5" object:self userInfo:@{@"buttonTag":[NSString stringWithFormat:@"%ld",(long)button.tag],@"buttonArray":self.buttonTitles}]; 242 | } 243 | 244 | @end 245 | -------------------------------------------------------------------------------- /两个滚动视图做界面/ButtonsView_CreateString.h: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonsView_CreateString.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/7/4. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "ButtonsView.h" 10 | 11 | @interface ButtonsView () 12 | @property (nonatomic, strong) UIButton* button1; 13 | @property (nonatomic, strong) UIButton* button2; 14 | @property (nonatomic, strong) UILabel* titleLabel; 15 | @property (nonatomic, strong) UILabel* leftLabel; 16 | @property (nonatomic, strong) UIView* view1; 17 | @property (nonatomic, strong) UIView* view2; 18 | 19 | //- (void)addAnimation; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /两个滚动视图做界面/DataModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // DataModel.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/29. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface DataModel : NSObject 12 | 13 | + (NSDictionary*)getNewsArray; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /两个滚动视图做界面/DataModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // DataModel.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/29. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "DataModel.h" 10 | 11 | @implementation DataModel 12 | 13 | + (NSDictionary*)getNewsArray 14 | { 15 | return @{@"广州":@{@"row":@"10",@"isImage":@"1",@"image":@"1.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"1",@"0"]}, 16 | @"深圳":@{@"row":@"8",@"isImage":@"0",@"image":@"5.jpg",@"type":@"地区",@"cell":@[@"0",@"0",@"1",@"0",@"0",@"1",@"0",@"1"]}, 17 | @"纪录片":@{@"row":@"3",@"isImage":@"0",@"image":@"2.jpg",@"type":@"推荐",@"cell":@[@"1",@"1",@"0"]}, 18 | @"财经":@{@"row":@"15",@"isImage":@"1",@"image":@"11.jpg",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 19 | @"娱乐":@{@"row":@"9",@"isImage":@"0",@"image":@"2.jpg",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 20 | @"要闻":@{@"row":@"2",@"isImage":@"1",@"image":@"3.jpg",@"type":@"推荐",@"cell":@[@"0",@"1"]}, 21 | @"体育":@{@"row":@"11",@"isImage":@"1",@"image":@"10.jpg",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 22 | @"汽车":@{@"row":@"7",@"isImage":@"1",@"image":@"4.jpg",@"type":@"推荐",@"cell":@[@"0",@"1",@"0",@"1",@"1",@"0",@"1"]}, 23 | @"图片":@{@"row":@"6",@"isImage":@"0",@"image":@"1.jpg",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"0"]}, 24 | @"科技":@{@"row":@"1",@"isImage":@"0",@"image":@"3.jpg",@"type":@"推荐",@"cell":@[@"1"]}, 25 | @"社会":@{@"row":@"14",@"isImage":@"1",@"image":@"8.png",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1"]}, 26 | @"读科学":@{@"row":@"10",@"isImage":@"0",@"image":@"6.png",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"0",@"1",@"0",@"1",@"1",@"0"]}, 27 | @"佛学":@{@"row":@"10",@"isImage":@"1",@"image":@"10.jpg",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 28 | @"军事":@{@"row":@"8",@"isImage":@"0",@"image":@"9.jpg",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0"]}, 29 | @"时尚":@{@"row":@"3",@"isImage":@"0",@"image":@"5.jpg",@"type":@"推荐",@"cell":@[@"1",@"1",@"0"]}, 30 | @"游戏":@{@"row":@"15",@"isImage":@"1",@"image":@"12.png",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 31 | @"房产":@{@"row":@"9",@"isImage":@"0",@"image":@"8.png",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 32 | @"数码":@{@"row":@"2",@"isImage":@"1",@"image":@"5.jpg",@"type":@"推荐",@"cell":@[@"1",@"0"]}, 33 | @"股票":@{@"row":@"11",@"isImage":@"1",@"image":@"4.jpg",@"type":@"推荐",@"cell":@[@"0",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 34 | @"国际":@{@"row":@"7",@"isImage":@"1",@"image":@"9.jpg",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0"]}, 35 | @"教育":@{@"row":@"6",@"isImage":@"0",@"image":@"7.jpg",@"type":@"推荐",@"cell":@[@"1",@"1",@"0",@"1",@"1",@"0",@"1"]}, 36 | @"电竞":@{@"row":@"1",@"isImage":@"0",@"image":@"5.jpg",@"type":@"推荐",@"cell":@[@"1"]}, 37 | @"电视剧":@{@"row":@"14",@"isImage":@"1",@"image":@"12.png",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 38 | @"重庆":@{@"row":@"10",@"isImage":@"1",@"image":@"7.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"1",@"0"]}, 39 | @"四川":@{@"row":@"8",@"isImage":@"0",@"image":@"6.png",@"type":@"地区",@"cell":@[@"0",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 40 | @"上海":@{@"row":@"3",@"isImage":@"0",@"image":@"6.png",@"type":@"地区",@"cell":@[@"1",@"1",@"0"]}, 41 | @"陕西":@{@"row":@"15",@"isImage":@"1",@"image":@"10.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 42 | @"山东":@{@"row":@"9",@"isImage":@"0",@"image":@"5.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"1"]}, 43 | @"浙江":@{@"row":@"2",@"isImage":@"1",@"image":@"1.jpg",@"type":@"地区",@"cell":@[@"0",@"1"]}, 44 | @"湖北":@{@"row":@"11",@"isImage":@"1",@"image":@"11.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0",@"0",@"1",@"0",@"1",@"1",@"0"]}, 45 | @"河南":@{@"row":@"7",@"isImage":@"1",@"image":@"10.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"0",@"1",@"1",@"0"]}, 46 | @"湖南":@{@"row":@"6",@"isImage":@"0",@"image":@"7.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"0",@"1",@"1",@"0"]}, 47 | @"福建":@{@"row":@"1",@"isImage":@"0",@"image":@"5.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"0",@"1",@"1",@"0",@"0",@"1",@"0",@"1",@"1",@"0",@"0",@"1",@"0",@"1",@"1",@"0",@"0",@"1",@"0",@"1",@"1",@"0"]}, 48 | @"江苏":@{@"row":@"14",@"isImage":@"1",@"image":@"1.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 49 | @"北京":@{@"row":@"10",@"isImage":@"0",@"image":@"11.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0"]}}; 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /两个滚动视图做界面/ImageCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // ImageCell.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ImageCell : UITableViewCell 12 | @property (strong, nonatomic) IBOutlet UILabel *topLabel; 13 | @property (strong, nonatomic) IBOutlet UILabel *bottomLabel1; 14 | @property (strong, nonatomic) IBOutlet UILabel *bottomLabel2; 15 | @property (strong, nonatomic) IBOutlet UIImageView *myImageVIew1; 16 | @property (strong, nonatomic) IBOutlet UIImageView *myImageView2; 17 | @property (strong, nonatomic) IBOutlet UIImageView *myImageView3; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /两个滚动视图做界面/ImageCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // ImageCell.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "ImageCell.h" 10 | 11 | @implementation ImageCell 12 | 13 | - (void)awakeFromNib { 14 | [super awakeFromNib]; 15 | // Initialization code 16 | } 17 | 18 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 19 | [super setSelected:selected animated:animated]; 20 | 21 | // Configure the view for the selected state 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /两个滚动视图做界面/ImageCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 49 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /两个滚动视图做界面/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /两个滚动视图做界面/MainViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MainViewController.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MainViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /两个滚动视图做界面/MainViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MainViewController.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "MainViewController.h" 10 | #import "TitleView.h" 11 | #import "MyTableViewController.h" 12 | #import "ButtonsTableViewController.h" 13 | #import "DataModel.h" 14 | 15 | 16 | #define WIDTH [UIScreen mainScreen].bounds.size.width 17 | #define HEIGHT self.view.bounds.size.height 18 | #define LINEWIGTH ((WIDTH/5) - 10) 19 | #define TOPVIEWWIGTH self.topView.frame.size.width 20 | 21 | @interface MainViewController () 22 | //最上面的滚动视图 23 | @property (nonatomic, strong) TitleView* topView; 24 | //最下面的滚动视图 25 | @property (nonatomic, strong) UIScrollView* bottomScrollView; 26 | @property (nonatomic, strong) NSArray* titles; 27 | //数组保存滚动视图里面的控制器 28 | @property (nonatomic, strong) NSArray* views; 29 | //表视图的表格形式和行数 30 | //@property (nonatomic, strong) NSArray* cellStatus; 31 | //记录滚动视图的按钮位置 32 | @property (nonatomic, unsafe_unretained) NSInteger buttonIndex; 33 | //直接点击滚动视图中的按钮 和 滑动两种状态下 34 | //@property (nonatomic, unsafe_unretained) BOOL isScroll; 35 | 36 | @end 37 | 38 | @implementation MainViewController 39 | 40 | 41 | - (TitleView*)topView 42 | { 43 | if (!_topView) 44 | { 45 | _topView = [[TitleView alloc]initWithFrame:CGRectMake(2, 0, WIDTH - 50, 40)]; 46 | _topView.myScrollView.delegate = self; 47 | _topView.backgroundColor = [UIColor clearColor]; 48 | } 49 | return _topView; 50 | } 51 | - (void)viewDidLoad 52 | { 53 | [super viewDidLoad]; 54 | // 关闭系统自动偏移 55 | self.automaticallyAdjustsScrollViewInsets = NO; 56 | 57 | [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(buttonChange3:) name:@"buttonChange3" object:nil]; 58 | [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeArray:) name:@"ChangeArray" object:nil]; 59 | } 60 | - (void)viewDidAppear:(BOOL)animated 61 | { 62 | // [self.topView removeScrollView]; 63 | [super viewDidAppear:animated]; 64 | NSUserDefaults* newsData = [NSUserDefaults standardUserDefaults]; 65 | self.titles = [newsData objectForKey:@"testArray"]; 66 | self.topView.buttonTitles = self.titles; 67 | self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)]; 68 | self.navigationItem.titleView = self.topView; 69 | [self.topView scrollView]; 70 | [self createScrollView]; 71 | [self showDurationForView]; 72 | } 73 | - (void)changeArray:(NSNotification*)notification 74 | { 75 | NSLog(@"...."); 76 | [self.topView removeScrollView]; 77 | self.titles = notification.userInfo[@"array"]; 78 | self.buttonIndex = [notification.userInfo[@"index"] integerValue]; 79 | [self createScrollView]; 80 | } 81 | //创建主滚动视图 82 | - (void)createScrollView 83 | { 84 | self.bottomScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, WIDTH, HEIGHT - 64)]; 85 | self.bottomScrollView.scrollsToTop = NO; 86 | self.bottomScrollView.delegate = self; 87 | self.bottomScrollView.contentSize = CGSizeMake(self.titles.count * WIDTH, HEIGHT - 64); 88 | self.bottomScrollView.userInteractionEnabled = YES; 89 | self.bottomScrollView.bounces = NO; 90 | self.bottomScrollView.scrollEnabled = YES; 91 | self.bottomScrollView.pagingEnabled = YES; 92 | self.bottomScrollView.showsHorizontalScrollIndicator = NO; 93 | self.bottomScrollView.showsVerticalScrollIndicator = NO; 94 | NSMutableArray* array = [NSMutableArray array]; 95 | for (int i = 0; i 3) 135 | { 136 | self.topView.myScrollView.contentOffset = CGPointMake(LINEWIGTH * r + 5*(2*self.buttonIndex+1), 0); 137 | } 138 | else 139 | { 140 | self.topView.myScrollView.contentOffset = CGPointMake(0, 0); 141 | } 142 | } 143 | //点击最上面滚动视图 改变下面滚动视图的变化 144 | - (void)buttonChange3:(NSNotification*)notification 145 | { 146 | NSInteger index = [notification.userInfo[@"buttonTag"] integerValue]; 147 | self.buttonIndex = index; 148 | CGPoint point = self.bottomScrollView.contentOffset; 149 | point.x = index * WIDTH; 150 | self.bottomScrollView.contentOffset = point; 151 | for (MyTableViewController* vc in self.views) 152 | { 153 | if (vc.view.tag == index) 154 | { 155 | [vc.tableView reloadData]; 156 | } 157 | } 158 | } 159 | #pragma mark - UIScrollViewDelegate 160 | 161 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView 162 | { 163 | if (scrollView == self.bottomScrollView) 164 | { 165 | CGPoint point = self.bottomScrollView.contentOffset; 166 | //取比率 167 | CGFloat r = point.x/WIDTH; 168 | //取整数 169 | NSInteger n = (NSInteger)point.x/WIDTH; 170 | self.buttonIndex = n; 171 | NSLog(@"大滚动视图滚动的距离 = %ld",(long)n); 172 | //当滚动距离大于0 173 | if (point.x > 0) 174 | { 175 | [UIView animateWithDuration:0.3 animations:^{ 176 | self.topView.bottomView.frame = CGRectMake(LINEWIGTH * r + 5*(2*n+1), self.topView.myScrollView.frame.size.height - 3, LINEWIGTH, 3); 177 | // NSLog(@"self.topView.bottomView.frame = %f",self.topView.bottomView.frame.origin.x); 178 | //当最上方的滚动视图滚动到第5个按钮的时候,需要把最上方的滚动视图向右滚动一段距离,以便第五个按钮看得见 179 | 180 | //正在拖拽的时候 181 | if (self.bottomScrollView.dragging) 182 | { 183 | if (n > 3) 184 | { 185 | self.topView.myScrollView.contentOffset = CGPointMake(LINEWIGTH * r + 5*(2*n+1), 0); 186 | } 187 | else 188 | { 189 | self.topView.myScrollView.contentOffset = CGPointMake(0, 0); 190 | } 191 | } 192 | for (UIButton* button in self.topView.allButtons) 193 | { 194 | if (button.tag == n) 195 | { 196 | [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 197 | } 198 | else 199 | { 200 | [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; 201 | } 202 | } 203 | }]; 204 | } 205 | } 206 | } 207 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 208 | 209 | { 210 | // Return YES for supported orientations 211 | return (interfaceOrientation == UIInterfaceOrientationPortrait); 212 | 213 | } 214 | 215 | 216 | @end 217 | -------------------------------------------------------------------------------- /两个滚动视图做界面/MyCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // MyCell.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MyCell : UITableViewCell 12 | @property (strong, nonatomic) IBOutlet UILabel *topLabel; 13 | @property (strong, nonatomic) IBOutlet UILabel *bottomLabel1; 14 | @property (strong, nonatomic) IBOutlet UILabel *bottomLabel2; 15 | @property (strong, nonatomic) IBOutlet UIImageView *myImageView; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /两个滚动视图做界面/MyCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // MyCell.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "MyCell.h" 10 | 11 | @implementation MyCell 12 | 13 | - (void)awakeFromNib { 14 | [super awakeFromNib]; 15 | // Initialization code 16 | } 17 | 18 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 19 | [super setSelected:selected animated:animated]; 20 | 21 | // Configure the view for the selected state 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /两个滚动视图做界面/MyCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 37 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /两个滚动视图做界面/MyTableViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MyTableViewController.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MyTableViewController : UITableViewController 12 | 13 | @property (nonatomic, strong) NSString* imageTitle; 14 | //测试行数 15 | @property (nonatomic, unsafe_unretained) NSInteger test; 16 | 17 | @property (nonatomic, unsafe_unretained) BOOL isImage; 18 | //按钮标题 19 | @property (nonatomic, strong) NSString* myTitle; 20 | 21 | @property (nonatomic, strong) NSArray* scrollViewImageTitles; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /两个滚动视图做界面/MyTableViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MyTableViewController.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "MyTableViewController.h" 10 | #import "MyCell.h" 11 | #import "ImageCell.h" 12 | #import "DataModel.h" 13 | 14 | @interface MyTableViewController () 15 | 16 | #define SCROLLVIEWWIDHT ([UIScreen mainScreen].bounds.size.width - 20) 17 | #define SCROLLVIEWHEIGHT self.headerScrollView.frame.size.height 18 | 19 | @property (strong, nonatomic) IBOutlet UIImageView *myImageView; 20 | @property (strong, nonatomic) IBOutlet UIScrollView *headerScrollView; 21 | @property (strong, nonatomic) IBOutlet UIPageControl *firstPageControl; 22 | 23 | @end 24 | 25 | @implementation MyTableViewController 26 | 27 | - (void)viewDidLoad 28 | { 29 | [super viewDidLoad]; 30 | 31 | [self.tableView registerNib:[UINib nibWithNibName:@"MyCell" bundle:nil] forCellReuseIdentifier:@"cell1"]; 32 | [self.tableView registerNib:[UINib nibWithNibName:@"ImageCell" bundle:nil] forCellReuseIdentifier:@"cell2"]; 33 | } 34 | 35 | - (void)createScrollView 36 | { 37 | self.headerScrollView.contentSize = CGSizeMake(SCROLLVIEWWIDHT * self.scrollViewImageTitles.count, SCROLLVIEWHEIGHT); 38 | for (int i = 0; i < self.scrollViewImageTitles.count; i++) 39 | { 40 | UIButton* button = [[UIButton alloc]init]; 41 | button.tag = i; 42 | button.frame = CGRectMake(SCROLLVIEWWIDHT * i, 0, SCROLLVIEWWIDHT, SCROLLVIEWHEIGHT); 43 | [button setTitle:@"" forState:UIControlStateNormal]; 44 | [button setBackgroundImage:[UIImage imageNamed:self.scrollViewImageTitles[i]] forState:UIControlStateNormal]; 45 | [button addTarget:self action:@selector(pushVC:) forControlEvents:UIControlEventTouchUpInside]; 46 | [self.headerScrollView addSubview:button]; 47 | } 48 | self.firstPageControl.numberOfPages = self.scrollViewImageTitles.count; 49 | self.firstPageControl.userInteractionEnabled = YES; 50 | } 51 | - (void)viewDidAppear:(BOOL)animated 52 | { 53 | [super viewDidAppear:animated]; 54 | if (self.isImage) 55 | { 56 | //头视图 是一张图片 57 | [self.firstPageControl setHidden:YES]; 58 | [self.myImageView setHidden:NO]; 59 | [self.headerScrollView setHidden:YES]; 60 | } 61 | else 62 | { 63 | //头视图 是一个滚动视图 64 | [self.firstPageControl setHidden:NO]; 65 | [self.myImageView setHidden:YES]; 66 | [self.headerScrollView setHidden:NO]; 67 | [self createScrollView]; 68 | } 69 | NSLog(@"图片名称 = %@",self.imageTitle); 70 | self.myImageView.image = [UIImage imageNamed:self.imageTitle]; 71 | } 72 | 73 | - (void)pushVC:(UIButton*)sender 74 | { 75 | NSLog(@"滚动视图按钮的tag值%ld",(long)sender.tag); 76 | } 77 | #pragma mark - UIScrollViewDelegate 78 | 79 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView 80 | { 81 | if (scrollView == self.headerScrollView) 82 | { 83 | CGPoint point = scrollView.contentOffset; 84 | self.firstPageControl.currentPage = (NSInteger)point.x/SCROLLVIEWHEIGHT; 85 | } 86 | } 87 | 88 | #pragma mark - Table view data source 89 | 90 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 91 | { 92 | return 1; 93 | } 94 | 95 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 96 | { 97 | return self.test; 98 | } 99 | - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 100 | { 101 | return 1.0; 102 | } 103 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 104 | { 105 | return [[DataModel getNewsArray][self.myTitle][@"cell"][indexPath.row] boolValue] ? 140.0 : 100.0; 106 | } 107 | 108 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 109 | { 110 | if ([[DataModel getNewsArray][self.myTitle][@"cell"][indexPath.row] boolValue]) 111 | { 112 | ImageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell2" forIndexPath:indexPath]; 113 | cell.myImageVIew1.image = [UIImage imageNamed:self.imageTitle]; 114 | cell.myImageView2.image = [UIImage imageNamed:self.imageTitle]; 115 | cell.myImageView3.image = [UIImage imageNamed:self.imageTitle]; 116 | return cell; 117 | } 118 | else 119 | { 120 | MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1" forIndexPath:indexPath]; 121 | cell.myImageView.image = [UIImage imageNamed:self.imageTitle]; 122 | return cell; 123 | } 124 | } 125 | 126 | @end 127 | -------------------------------------------------------------------------------- /两个滚动视图做界面/MyTableViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 33 | 34 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /两个滚动视图做界面/TRButton.h: -------------------------------------------------------------------------------- 1 | // 2 | // TRButton.h 3 | // 拖拽排列按钮 4 | // 5 | // Created by leiyu on 15/8/27. 6 | // Copyright (c) 2015年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class TRButton; 12 | @protocol TRButtonDelegate 13 | 14 | - (void) dragButton:(TRButton*)button buttons:(NSArray*)buttons; 15 | - (void) dragButton1:(TRButton *)button buttons:(NSArray *)buttons; 16 | 17 | @end 18 | 19 | @interface TRButton : UIButton 20 | @property (nonatomic ,strong) id delegate; 21 | //存放需要拖拽的按钮数组 22 | @property (nonatomic ,strong) NSMutableArray* btnArray; 23 | 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /两个滚动视图做界面/TRButton.m: -------------------------------------------------------------------------------- 1 | // 2 | // TRButton.m 3 | // 拖拽排列按钮 4 | // 5 | // Created by leiyu on 15/8/27. 6 | // Copyright (c) 2015年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "TRButton.h" 10 | #import "DataModel.h" 11 | @interface TRButton () 12 | 13 | #define WIDTH [UIScreen mainScreen].bounds.size.width 14 | //被拖动按钮的下标 15 | @property (nonatomic ,unsafe_unretained) NSInteger dragIndex; 16 | //被拖动按钮的中心点 17 | @property (nonatomic ,unsafe_unretained) CGPoint dragCenter; 18 | //按钮的背景颜色 19 | @property (nonatomic ,strong) UIColor* bgColor; 20 | //所有拖动按钮 21 | @property (nonatomic ,strong) NSMutableArray* dragButtons; 22 | //长安手势刚触碰时的坐标 23 | @property (nonatomic ,unsafe_unretained)CGPoint startPoint; 24 | //准备拖动的按钮开始下标 25 | @property (nonatomic ,unsafe_unretained)NSInteger startIndex; 26 | @property (nonatomic ,strong) UIView* displayView; 27 | @property (nonatomic ,strong) UIButton* topView; 28 | @property (nonatomic ,strong) UIButton* bottomView; 29 | 30 | @end 31 | @implementation TRButton 32 | - (instancetype) initWithFrame:(CGRect)frame 33 | { 34 | if (self=[super initWithFrame:frame]) 35 | { 36 | UILongPressGestureRecognizer* longGR=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(buttonLongPressed:)]; 37 | [self addGestureRecognizer:longGR]; 38 | [self addTarget:self action:@selector(changeCount:) forControlEvents:UIControlEventTouchUpInside]; 39 | } 40 | return self; 41 | } 42 | - (void)setBtnArray:(NSMutableArray *)btnArray 43 | { 44 | _btnArray=btnArray; 45 | for (TRButton* button in btnArray) 46 | { 47 | button.dragButtons=btnArray; 48 | } 49 | } 50 | - (void)changeCount:(TRButton*)sender 51 | { 52 | NSLog(@"buttons = %ld",(unsigned long)self.dragButtons.count); 53 | if (self.dragButtons.count > 2) 54 | { 55 | //如果按钮数组里面的按钮个数大于2时,可以对其进行删除 56 | //被点击的按钮的中心点 57 | self.dragCenter=self.center; 58 | self.dragIndex=[self.dragButtons indexOfObject:self]; 59 | [self removeButton:self]; 60 | //用于判断对象是否拥有参数提供的方法 61 | if ([self.delegate respondsToSelector:@selector(dragButton1:buttons:)]) 62 | { 63 | [self.delegate dragButton1:self buttons:self.dragButtons]; 64 | } 65 | } 66 | else 67 | { 68 | //如果 只剩下两个频道点击不能删除 69 | for (UIButton* button in self.dragButtons) 70 | { 71 | if (button.tag == sender.tag) 72 | { 73 | [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; 74 | } 75 | else 76 | { 77 | [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 78 | } 79 | } 80 | } 81 | } 82 | 83 | //调整按钮位置 84 | - (void)removeButton:(UIButton*)dragButton 85 | { 86 | __block CGPoint oldCenter=self.dragCenter; 87 | __block CGPoint nextCenter=CGPointZero; 88 | //将靠后的按钮移动到靠前的位置 89 | for (NSInteger num=self.dragIndex+1; num=index; num--) 190 | { 191 | //执行动画过程 192 | [UIView animateWithDuration:0.2 animations:^{ 193 | UIButton* nextButton=[self.dragButtons objectAtIndex:num]; 194 | nextCenter=nextButton.center; 195 | nextButton.center=oldCenter; 196 | oldCenter=nextCenter; 197 | }]; 198 | } 199 | //调整顺序; 200 | //把拖拽的按钮插入到移动过的按钮的位置 201 | [self.dragButtons insertObject:dragButton atIndex:index]; 202 | //删除原来拖拽的按钮的位置(因为原来的按钮已经拖拽到其他地方去了,把多余的原来的按钮从数组中去除) 203 | [self.dragButtons removeObjectAtIndex:self.dragIndex+1]; 204 | } 205 | //如果经过的按钮的下标 比被拖拽的按钮的下标大 206 | else 207 | { 208 | //将靠后的按钮移动到靠前的位置 209 | for (NSInteger num=self.dragIndex+1; num<=index; num++) 210 | { 211 | //执行动画过程 212 | [UIView animateWithDuration:0.2 animations:^{ 213 | UIButton* nextButton=[self.dragButtons objectAtIndex:num]; 214 | nextCenter=nextButton.center; 215 | nextButton.center=oldCenter; 216 | oldCenter=nextCenter; 217 | }]; 218 | 219 | } 220 | //调整顺序; 221 | //把拖拽的按钮插入到移动过的按钮的位置 222 | [self.dragButtons insertObject:dragButton atIndex:index+1]; 223 | //删除原来拖拽的按钮的位置(因为原来的按钮已经拖拽到其他地方去了,把多余的原来的按钮从数组中去除) 224 | [self.dragButtons removeObjectAtIndex:self.dragIndex]; 225 | } 226 | self.dragIndex=index; 227 | self.dragCenter=moveCenter; 228 | } 229 | //拖拽结束的时候 230 | - (void)touchesEnded:(UILongPressGestureRecognizer*)gr 231 | { 232 | [UIView animateWithDuration:0.2 animations:^{ 233 | self.backgroundColor=self.bgColor; 234 | self.transform=CGAffineTransformIdentity; 235 | self.center=self.dragCenter; 236 | }]; 237 | // 判断按钮位置是否已经改变,如果发生改变通过代理通知父视图 238 | if (self.startIndex!=self.dragIndex) 239 | { 240 | //用于判断对象是否拥有参数提供的方法 参数示例: @selector(test) or @selector(testById:) 241 | if ([self.delegate respondsToSelector:@selector(dragButton:buttons:)]) 242 | { 243 | [self.delegate dragButton:self buttons:self.dragButtons]; 244 | } 245 | } 246 | } 247 | ////CABasicAnimation的代理方法 248 | //- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag 249 | //{ 250 | // if ([[anim valueForKey:@"animationType"] isEqualToString:@"close"]) 251 | // { 252 | // [self.displayView removeFromSuperview]; 253 | // [self.topView removeFromSuperview]; 254 | // [self.bottomView removeFromSuperview]; 255 | // 256 | // self.displayView=nil; 257 | // self.bottomView=nil; 258 | // self.topView=nil; 259 | // } 260 | //} 261 | 262 | @end 263 | -------------------------------------------------------------------------------- /两个滚动视图做界面/TitleView.h: -------------------------------------------------------------------------------- 1 | // 2 | // TitleView.h 3 | // 华康通 4 | // 5 | // Created by 雷雨 on 16/4/19. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TitleView : UIView 12 | 13 | @property (nonatomic, strong) UIScrollView* myScrollView; 14 | @property (nonatomic, strong) NSArray* buttonTitles; 15 | @property (nonatomic, strong) NSMutableArray* allButtons; 16 | @property (nonatomic, strong) UIView* bottomView; 17 | 18 | - (void)scrollView; 19 | - (void)removeScrollView; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /两个滚动视图做界面/TitleView.m: -------------------------------------------------------------------------------- 1 | // 2 | // TitleView.m 3 | // 华康通 4 | // 5 | // Created by 雷雨 on 16/4/19. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "TitleView.h" 10 | 11 | #define SCREENWIDTH [UIScreen mainScreen].bounds.size.width 12 | 13 | @implementation TitleView 14 | 15 | 16 | - (NSMutableArray*)allButtons 17 | { 18 | if (!_allButtons) 19 | { 20 | _allButtons = [NSMutableArray array]; 21 | } 22 | return _allButtons; 23 | } 24 | 25 | //更新表格 26 | - (void)changeData:(UIButton*)sender 27 | { 28 | for (UIButton* button in self.allButtons) 29 | { 30 | if (button.tag == sender.tag) 31 | { 32 | [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 33 | } 34 | else 35 | { 36 | [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; 37 | } 38 | [self animationForViewWithButton:sender withTag:sender.tag]; 39 | } 40 | [[NSNotificationCenter defaultCenter]postNotificationName:@"buttonChange3" object:self userInfo:@{@"buttonTag":[NSString stringWithFormat:@"%ld",(long)sender.tag],@"buttonArray":self.allButtons}]; 41 | } 42 | - (void)scrollView 43 | { 44 | self.myScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; 45 | 46 | self.myScrollView.contentSize = CGSizeMake(self.buttonTitles.count * SCREENWIDTH / 5, self.frame.size.height); 47 | self.myScrollView.userInteractionEnabled = YES; 48 | self.myScrollView.bounces = YES; 49 | self.myScrollView.scrollEnabled = YES; 50 | self.myScrollView.pagingEnabled = NO; 51 | self.myScrollView.showsHorizontalScrollIndicator = NO; 52 | self.myScrollView.showsVerticalScrollIndicator = NO; 53 | for (int i = 0; i 10 | 11 | @interface UIColor (SelfColor) 12 | 13 | + (UIColor *)getColor:(NSString *)hexColor; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /两个滚动视图做界面/UIColor+SelfColor.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+SelfColor.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/7/4. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "UIColor+SelfColor.h" 10 | 11 | @implementation UIColor (SelfColor) 12 | 13 | + (UIColor *)getColor:(NSString *)hexColor 14 | { 15 | unsigned int red,green,blue; 16 | NSRange range; 17 | range.length = 2; 18 | 19 | range.location = 0; 20 | [[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&red]; 21 | 22 | range.location = 2; 23 | [[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&green]; 24 | 25 | range.location = 4; 26 | [[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&blue]; 27 | 28 | return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green / 255.0f) blue:(float)(blue / 255.0f) alpha:1.0f]; 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /两个滚动视图做界面/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /两个滚动视图做界面Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /两个滚动视图做界面Tests/_________Tests.m: -------------------------------------------------------------------------------- 1 | // 2 | // _________Tests.m 3 | // 两个滚动视图做界面Tests 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface _________Tests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation _________Tests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /两个滚动视图做界面UITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /两个滚动视图做界面UITests/_________UITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // _________UITests.m 3 | // 两个滚动视图做界面UITests 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface _________UITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation _________UITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面.xcodeproj/project.xcworkspace/xcuserdata/leiyu.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面.xcodeproj/project.xcworkspace/xcuserdata/leiyu.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面.xcodeproj/xcuserdata/leiyu.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面.xcodeproj/xcuserdata/leiyu.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 两个滚动视图做界面.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | E64DAD9A1D20D10800A47890 16 | 17 | primary 18 | 19 | 20 | E64DADB31D20D10800A47890 21 | 22 | primary 23 | 24 | 25 | E64DADBE1D20D10800A47890 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面.xcodeproj/xcuserdata/leiyu.xcuserdatad/xcschemes/两个滚动视图做界面.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/1.jpg -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/10.jpg -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/11.jpg -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/12.png -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/2.jpg -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/3.jpg -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/4.jpg -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/5.jpg -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/6.png -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/7.jpg -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/8.png -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leiyu880904/TwoScrollVC/4005ba74f7e8cd8849d47e94179c13572e2487a7/两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/9.jpg -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "UIColor+SelfColor.h" 11 | 12 | @interface AppDelegate () 13 | 14 | @end 15 | 16 | @implementation AppDelegate 17 | 18 | 19 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 20 | { 21 | [[UINavigationBar appearance]setBarTintColor:[UIColor whiteColor]]; 22 | [[UINavigationBar appearance]setTintColor:[UIColor getColor:@"EF7000"]]; 23 | [[UINavigationBar appearance]setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:17],NSForegroundColorAttributeName:[UIColor blackColor]}]; 24 | return YES; 25 | } 26 | 27 | - (void)applicationWillResignActive:(UIApplication *)application { 28 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 29 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 30 | } 31 | 32 | - (void)applicationDidEnterBackground:(UIApplication *)application { 33 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 34 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 35 | } 36 | 37 | - (void)applicationWillEnterForeground:(UIApplication *)application { 38 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 39 | } 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 43 | } 44 | 45 | - (void)applicationWillTerminate:(UIApplication *)application { 46 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/ButtonsCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonsCell.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/28. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ButtonsCell : UITableViewCell 12 | @property (strong, nonatomic) IBOutlet UILabel *myLabel; 13 | @property (strong, nonatomic) IBOutlet UIButton *myButton; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/ButtonsCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonsCell.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/28. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "ButtonsCell.h" 10 | 11 | @implementation ButtonsCell 12 | 13 | - (void)awakeFromNib { 14 | [super awakeFromNib]; 15 | // Initialization code 16 | } 17 | 18 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 19 | [super setSelected:selected animated:animated]; 20 | 21 | // Configure the view for the selected state 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/ButtonsCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 28 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/ButtonsTableViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonsTableViewController.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/28. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ButtonsTableViewController : UITableViewController 12 | 13 | @property (nonatomic, strong) NSArray* buttonTitles; 14 | @property (nonatomic, unsafe_unretained) NSInteger buttonIndex; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/ButtonsTableViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonsTableViewController.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/28. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "ButtonsTableViewController.h" 10 | #import "ButtonsCell.h" 11 | #import "ButtonsView.h" 12 | #import "DataModel.h" 13 | 14 | #define WIDTH [UIScreen mainScreen].bounds.size.width 15 | #define KONGWIDTH (WIDTH - 4*60)/5 16 | 17 | @interface ButtonsTableViewController () 18 | @property (nonatomic, strong) NSArray* testArray1; 19 | @property (nonatomic, strong) NSArray* testArray2; 20 | @property (nonatomic, unsafe_unretained) NSInteger isLeft; 21 | @property (nonatomic, strong) UIView* view1; 22 | @property (nonatomic, strong) UIView* view2; 23 | @property (nonatomic, strong) ButtonsView* buttonsView; 24 | 25 | @property (nonatomic, strong) NSString* myTitle; 26 | 27 | @end 28 | 29 | @implementation ButtonsTableViewController 30 | 31 | - (ButtonsView*)buttonsView 32 | { 33 | if (!_buttonsView) 34 | { 35 | _buttonsView = [[ButtonsView alloc]init]; 36 | } 37 | return _buttonsView; 38 | } 39 | - (NSArray*)testArray1 40 | { 41 | if (!_testArray1) 42 | { 43 | _testArray1 = @[@"佛学",@"军事",@"时尚",@"游戏",@"房产",@"数码",@"股票",@"国际",@"教育",@"电竞",@"电视剧"]; 44 | } 45 | return _testArray1; 46 | } 47 | - (NSArray*)testArray2 48 | { 49 | if (!_testArray2) 50 | { 51 | _testArray2 = @[@"重庆",@"四川",@"上海",@"陕西",@"山东",@"浙江",@"湖北",@"河南",@"湖南",@"福建",@"江苏",@"北京"]; 52 | } 53 | return _testArray2; 54 | } 55 | 56 | - (void)viewDidLoad 57 | { 58 | [super viewDidLoad]; 59 | self.title = @"频道定制"; 60 | self.myTitle = [self getTitle]; 61 | [self createHeaderView]; 62 | self.tableView.tableHeaderView = self.buttonsView; 63 | self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action:@selector(goBack)]; 64 | [self.tableView registerNib:[UINib nibWithNibName:@"ButtonsCell" bundle:nil] forCellReuseIdentifier:@"cell"]; 65 | [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(buttonChange:) name:@"buttonChange" object:nil]; 66 | [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(buttonChange1:) name:@"buttonChange1" object:nil]; 67 | [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(buttonChange5:) name:@"buttonChange5" object:nil]; 68 | } 69 | 70 | - (void)viewDidAppear:(BOOL)animated 71 | { 72 | self.isLeft = 0; 73 | 74 | } 75 | //创建头视图(规矩排列的按钮组) 76 | - (void)createHeaderView 77 | { 78 | self.buttonsView.buttonTitles = self.buttonTitles; 79 | self.buttonsView.index = self.isLeft; 80 | self.buttonsView.buttonTitles1 = @[@"推荐频道",@"地方频道"]; 81 | [self.buttonsView createButtons]; 82 | } 83 | //点击表视图头部的按钮 84 | - (void)buttonChange:(NSNotification*)notification 85 | { 86 | NSLog(@"点击表视图头部的按钮"); 87 | NSInteger index = [notification.userInfo[@"buttonTag"] integerValue]; 88 | if ([[DataModel getNewsArray][self.buttonTitles[index]][@"type"] isEqualToString:@"推荐"]) 89 | { 90 | NSMutableArray* array = [NSMutableArray arrayWithArray:self.testArray1]; 91 | [array insertObject:self.buttonTitles[index] atIndex:0]; 92 | self.testArray1 = [array copy]; 93 | self.isLeft = 0; 94 | } 95 | else 96 | { 97 | NSMutableArray* array = [NSMutableArray arrayWithArray:self.testArray2]; 98 | [array insertObject:self.buttonTitles[index] atIndex:0]; 99 | self.testArray2 = [array copy]; 100 | self.isLeft = 1; 101 | } 102 | NSLog(@"点击了哪个按钮 %ld",index); 103 | NSLog(@"点击的按钮标题 %@",self.buttonTitles[index]); 104 | // self.buttonTitles = notification.userInfo[@"buttonArray"] 105 | [self.buttonsView removeAllButtons]; 106 | [self.buttonsView removeAllButtons1]; 107 | self.buttonTitles = notification.userInfo[@"buttonArray"]; 108 | self.buttonsView.buttonTitles = notification.userInfo[@"buttonArray"]; 109 | self.buttonsView.index = self.isLeft; 110 | self.buttonsView.buttonTitles1 = @[@"推荐频道",@"地方频道"]; 111 | [self.buttonsView createButtons]; 112 | dispatch_async(dispatch_get_main_queue(), ^{ 113 | self.tableView.tableHeaderView = self.buttonsView; 114 | [self.tableView reloadData]; 115 | }); 116 | } 117 | 118 | //改变按钮位置 重新排列数组 得到新的数组 119 | - (void)buttonChange5:(NSNotification*)notification 120 | { 121 | NSLog(@"改变按钮位置 重新排列数组 得到新的数组"); 122 | [self.buttonsView removeAllButtons]; 123 | [self.buttonsView removeAllButtons1]; 124 | self.buttonTitles = notification.userInfo[@"buttonArray"]; 125 | self.buttonsView.buttonTitles = notification.userInfo[@"buttonArray"]; 126 | self.buttonsView.index = self.isLeft; 127 | self.buttonsView.buttonTitles1 = @[@"推荐频道",@"地方频道"]; 128 | [self.buttonsView createButtons]; 129 | dispatch_async(dispatch_get_main_queue(), ^{ 130 | self.tableView.tableHeaderView = self.buttonsView; 131 | [self.tableView reloadData]; 132 | }); 133 | } 134 | //点击频道 135 | - (void)buttonChange1:(NSNotification*)notification 136 | { 137 | self.isLeft = [notification.userInfo[@"buttonTag"] integerValue]; 138 | NSLog(@"点击了哪个频道 %ld",self.isLeft); 139 | [self.tableView reloadData]; 140 | } 141 | - (void)goBack 142 | { 143 | [[NSNotificationCenter defaultCenter]postNotificationName:@"ChangeArray" object:self userInfo:@{@"array":self.buttonTitles,@"index":[NSString stringWithFormat:@"%ld",[self getIndex]]}]; 144 | [self dismissViewControllerAnimated:YES completion:nil]; 145 | } 146 | //添加频道 147 | - (void)addData:(UIButton*)sender 148 | { 149 | [self.buttonsView removeAllButtons]; 150 | [self.buttonsView removeAllButtons1]; 151 | self.buttonTitles = self.buttonsView.buttonTitles; 152 | ButtonsCell *cell = (ButtonsCell*)[[sender superview]superview]; 153 | NSMutableArray* array = [NSMutableArray arrayWithArray:self.buttonTitles]; 154 | [array addObject:cell.myLabel.text]; 155 | self.buttonTitles = [array copy]; 156 | [self createHeaderView]; 157 | //删除行 158 | if (self.isLeft == 0) 159 | { 160 | NSMutableArray* array = [NSMutableArray arrayWithArray:self.testArray1]; 161 | [array removeObject:cell.myLabel.text]; 162 | // [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; 163 | self.testArray1 = [array copy]; 164 | } 165 | else 166 | { 167 | NSMutableArray* array = [NSMutableArray arrayWithArray:self.testArray2]; 168 | [array removeObject:cell.myLabel.text]; 169 | // [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; 170 | self.testArray2 = [array copy]; 171 | } 172 | dispatch_async(dispatch_get_main_queue(), ^{ 173 | self.tableView.tableHeaderView = self.buttonsView; 174 | [self.tableView reloadData]; 175 | }); 176 | } 177 | //刚加载完成的时候得到 上个页面的下标对应的title 178 | - (NSString*)getTitle 179 | { 180 | NSString* title = self.buttonTitles[self.buttonIndex]; 181 | return title; 182 | } 183 | //根据按钮的文字 获得在新数组里面的位置 184 | - (NSInteger)getIndex 185 | { 186 | if ([self.buttonTitles containsObject:self.myTitle]) 187 | { 188 | NSInteger index = [self.buttonTitles indexOfObject:self.myTitle]; 189 | return index; 190 | } 191 | else 192 | { 193 | return 0; 194 | } 195 | } 196 | #pragma mark - Table view data source 197 | 198 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 199 | { 200 | return 1; 201 | } 202 | 203 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 204 | { 205 | return self.isLeft == 0 ? self.testArray1.count : self.testArray2.count; 206 | } 207 | 208 | - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 209 | { 210 | return 1.0; 211 | } 212 | 213 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 214 | { 215 | ButtonsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath]; 216 | [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 217 | if (self.isLeft == 0) 218 | { 219 | cell.myLabel.text = self.testArray1[indexPath.row]; 220 | } 221 | else 222 | { 223 | cell.myLabel.text = self.testArray2[indexPath.row]; 224 | } 225 | [cell.myButton addTarget:self action:@selector(addData:) forControlEvents:UIControlEventTouchUpInside]; 226 | return cell; 227 | } 228 | 229 | 230 | @end 231 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/ButtonsTableViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/ButtonsView.h: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonsView.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/28. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ButtonsView : UIView 12 | 13 | @property (nonatomic, strong) NSArray* buttonTitles; 14 | @property (nonatomic, strong) NSArray* buttonTitles1; 15 | @property (nonatomic, strong) NSMutableArray* allButtons; 16 | @property (nonatomic, strong) NSMutableArray* allButtons1; 17 | @property (nonatomic, strong) NSMutableArray* views; 18 | //一个判断是哪个按钮被按下的判断值 19 | @property (nonatomic, unsafe_unretained) NSInteger index; 20 | 21 | @property (nonatomic, strong) UIButton* moveButton; 22 | 23 | - (void)removeAllButtons; 24 | - (void)createButtons; 25 | - (void)removeAllButtons1; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/ButtonsView.m: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonsView.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/28. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "ButtonsView.h" 10 | #import "TRButton.h" 11 | #import "ButtonsView_CreateString.h" 12 | 13 | #define WIDTH [UIScreen mainScreen].bounds.size.width 14 | #define KONGWIDTH (WIDTH - 4*60)/5 15 | 16 | @interface ButtonsView () 17 | 18 | @end 19 | @implementation ButtonsView 20 | - (UILabel*)leftLabel 21 | { 22 | if (!_leftLabel) 23 | { 24 | _leftLabel = [[UILabel alloc]initWithFrame:CGRectMake(KONGWIDTH, 20, 100, 20)]; 25 | _leftLabel.text = @"已选频道"; 26 | _leftLabel.textAlignment = NSTextAlignmentLeft; 27 | _leftLabel.font = [UIFont systemFontOfSize:14]; 28 | _leftLabel.textColor = [UIColor colorWithRed:220.0/255.0 green:220.0/255.0 blue:220.0/255.0 alpha:1.0]; 29 | } 30 | return _leftLabel; 31 | } 32 | - (UILabel*)titleLabel 33 | { 34 | if (!_titleLabel) 35 | { 36 | _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH -150 - KONGWIDTH, 20, 150, 20)]; 37 | _titleLabel.text = @"按住拖动调整排序"; 38 | _titleLabel.textAlignment = NSTextAlignmentRight; 39 | _titleLabel.font = [UIFont systemFontOfSize:14]; 40 | _titleLabel.textColor = [UIColor colorWithRed:220.0/255.0 green:220.0/255.0 blue:220.0/255.0 alpha:1.0]; 41 | } 42 | return _titleLabel; 43 | } 44 | - (NSMutableArray*)allButtons 45 | { 46 | if (!_allButtons) 47 | { 48 | _allButtons = [NSMutableArray array]; 49 | } 50 | return _allButtons; 51 | } 52 | - (NSMutableArray*)allButtons1 53 | { 54 | if (!_allButtons1) 55 | { 56 | _allButtons1 = [NSMutableArray array]; 57 | } 58 | return _allButtons1; 59 | } 60 | - (NSMutableArray*)views 61 | { 62 | if (!_views) 63 | { 64 | _views = [NSMutableArray array]; 65 | } 66 | return _views; 67 | } 68 | - (id)init 69 | { 70 | if (self = [super init]) 71 | { 72 | self.backgroundColor = [UIColor whiteColor]; 73 | } 74 | return self; 75 | } 76 | 77 | - (void)createButtons 78 | { 79 | [self addSubview:self.leftLabel]; 80 | [self addSubview:self.titleLabel]; 81 | for (int i = 0; i < self.buttonTitles.count; i++) 82 | { 83 | //代表第几行 84 | NSInteger n = (NSInteger)i/4; 85 | //代表第几列 86 | NSInteger l = (NSInteger)i%4; 87 | TRButton* button=[TRButton buttonWithType:UIButtonTypeCustom]; 88 | button.delegate=self; 89 | button.tag = i; 90 | button.userInteractionEnabled = YES; 91 | button.frame = CGRectMake(((KONGWIDTH + 60) * l) + KONGWIDTH, (n * (KONGWIDTH + 30)) + 20 + 40, 60, 30); 92 | [button setTitle:self.buttonTitles[i] forState:UIControlStateNormal]; 93 | [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 94 | button.layer.borderWidth = 0.3; 95 | button.layer.borderColor = [UIColor colorWithRed:200.0/255.0 green:200.0/255.0 blue:200.0/255.0 alpha:1.0].CGColor; 96 | button.layer.cornerRadius = 3.0; 97 | button.layer.masksToBounds = YES; 98 | [button setBackgroundColor:[UIColor whiteColor]]; 99 | [button addTarget:self action:@selector(changeCount:) forControlEvents:UIControlEventTouchUpInside]; 100 | [self.allButtons addObject:button]; 101 | button.btnArray = self.allButtons; 102 | [self addSubview:button]; 103 | CGFloat height = button.frame.origin.y; 104 | CGFloat viewHeight = height + 50 + 30 + 40; 105 | self.frame = CGRectMake(0, 0, WIDTH, viewHeight); 106 | } 107 | self.button1 = [[UIButton alloc]init]; 108 | self.button1.tag = 0; 109 | self.button1.frame = CGRectMake((((WIDTH - 2*80)/3) + 80) * 0 + ((WIDTH - 2*80)/3), self.frame.size.height - 30, 80, 30); 110 | [self.button1 setTitle:self.buttonTitles1[0] forState:UIControlStateNormal]; 111 | [self.button1 setBackgroundColor:[UIColor whiteColor]]; 112 | self.view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 28, 80, 2)]; 113 | if (self.index == 0) 114 | { 115 | [self.button1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; 116 | self.view1.hidden = NO; 117 | } 118 | else 119 | { 120 | [self.button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 121 | self.view1.hidden = YES; 122 | } 123 | self.view1.tag = 0; 124 | self.view1.backgroundColor = [UIColor orangeColor]; 125 | [self.views addObject:self.view1]; 126 | [self.allButtons1 addObject:self.button1]; 127 | [self.button1 addSubview:self.view1]; 128 | [self.button1 addTarget:self action:@selector(showLeftData:) forControlEvents:UIControlEventTouchUpInside]; 129 | [self addSubview:self.button1]; 130 | 131 | self.button2 = [[UIButton alloc]init]; 132 | self.button2.tag = 1; 133 | self.button2.frame = CGRectMake((((WIDTH - 2*80)/3) + 80) * 1 + ((WIDTH - 2*80)/3), self.frame.size.height - 30, 80, 30); 134 | [self.button2 setTitle:self.buttonTitles1[1] forState:UIControlStateNormal]; 135 | [self.button2 setBackgroundColor:[UIColor whiteColor]]; 136 | self.view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 28, 80, 2)]; 137 | if (self.index == 1) 138 | { 139 | [self.button2 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; 140 | self.view2.hidden = NO; 141 | } 142 | else 143 | { 144 | [self.button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 145 | self.view2.hidden = YES; 146 | } 147 | self.view2.tag = 1; 148 | self.view2.backgroundColor = [UIColor orangeColor]; 149 | [self.views addObject:self.view2]; 150 | [self.allButtons1 addObject:self.button2]; 151 | [self.button2 addSubview:self.view2]; 152 | [self.button2 addTarget:self action:@selector(showLeftData:) forControlEvents:UIControlEventTouchUpInside]; 153 | [self addSubview:self.button2]; 154 | } 155 | //推荐频道和地方频道 156 | - (void)showLeftData:(UIButton*)sender 157 | { 158 | for (UIView* view in self.views) 159 | { 160 | if (view.tag == sender.tag) 161 | { 162 | view.hidden = NO; 163 | } 164 | else 165 | { 166 | view.hidden = YES; 167 | } 168 | } 169 | for (UIButton* button in self.allButtons1) 170 | { 171 | if (button.tag == sender.tag) 172 | { 173 | [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; 174 | } 175 | else 176 | { 177 | [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 178 | } 179 | } 180 | [[NSNotificationCenter defaultCenter]postNotificationName:@"buttonChange1" object:self userInfo:@{@"buttonTag":[NSString stringWithFormat:@"%ld",(long)sender.tag]}]; 181 | } 182 | 183 | - (void)changeCount:(TRButton*)sender 184 | { 185 | for (UIButton* button in self.allButtons) 186 | { 187 | if (button.tag == sender.tag) 188 | { 189 | [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; 190 | } 191 | else 192 | { 193 | [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 194 | } 195 | } 196 | NSMutableArray* array = [NSMutableArray arrayWithArray:self.buttonTitles]; 197 | [array removeObjectAtIndex:sender.tag]; 198 | self.buttonTitles = [array copy]; 199 | [[NSNotificationCenter defaultCenter]postNotificationName:@"buttonChange" object:self userInfo:@{@"buttonTag":[NSString stringWithFormat:@"%ld",(long)sender.tag],@"buttonArray":self.buttonTitles}]; 200 | } 201 | - (void)removeAllButtons1 202 | { 203 | for (TRButton* button in self.allButtons) 204 | { 205 | [button removeFromSuperview]; 206 | } 207 | [self.allButtons removeAllObjects]; 208 | } 209 | - (void)removeAllButtons 210 | { 211 | for (UIButton* button in self.allButtons1) 212 | { 213 | [button removeFromSuperview]; 214 | } 215 | [self.allButtons1 removeAllObjects]; 216 | } 217 | 218 | //得到变化后的按钮数组 219 | - (void)dragButton:(TRButton *)button buttons:(NSArray *)buttons 220 | { 221 | // self.allButtons = [NSMutableArray arrayWithArray:buttons]; 222 | NSLog(@"buttons = %@",buttons); 223 | NSString* currentTitle=button.currentTitle; 224 | NSLog(@"%@位置发生了改变,counts=%lu",currentTitle,(unsigned long)button.tag); 225 | NSMutableArray* array = [NSMutableArray arrayWithArray:self.buttonTitles]; 226 | if ([buttons containsObject:button]) 227 | { 228 | NSInteger index = [buttons indexOfObject:button]; 229 | [array removeObjectAtIndex:button.tag]; 230 | [array insertObject:currentTitle atIndex:index]; 231 | self.buttonTitles = [array copy]; 232 | NSLog(@"index = %ld",index); 233 | } 234 | [[NSNotificationCenter defaultCenter]postNotificationName:@"buttonChange5" object:self userInfo:@{@"buttonTag":[NSString stringWithFormat:@"%ld",(long)button.tag],@"buttonArray":self.buttonTitles}]; 235 | } 236 | 237 | @end 238 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/ButtonsView_CreateString.h: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonsView_CreateString.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/7/4. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "ButtonsView.h" 10 | 11 | @interface ButtonsView () 12 | @property (nonatomic, strong) UIButton* button1; 13 | @property (nonatomic, strong) UIButton* button2; 14 | @property (nonatomic, strong) UILabel* titleLabel; 15 | @property (nonatomic, strong) UILabel* leftLabel; 16 | @property (nonatomic, strong) UIView* view1; 17 | @property (nonatomic, strong) UIView* view2; 18 | 19 | //- (void)addAnimation; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/DataModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // DataModel.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/29. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface DataModel : NSObject 12 | 13 | + (NSDictionary*)getNewsArray; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/DataModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // DataModel.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/29. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "DataModel.h" 10 | 11 | @implementation DataModel 12 | 13 | + (NSDictionary*)getNewsArray 14 | { 15 | return @{@"广州":@{@"row":@"10",@"isImage":@"1",@"image":@"1.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"1",@"0"]}, 16 | @"深圳":@{@"row":@"8",@"isImage":@"0",@"image":@"5.jpg",@"type":@"地区",@"cell":@[@"0",@"0",@"1",@"0",@"0",@"1",@"0",@"1"]}, 17 | @"纪录片":@{@"row":@"3",@"isImage":@"0",@"image":@"2.jpg",@"type":@"推荐",@"cell":@[@"1",@"1",@"0"]}, 18 | @"财经":@{@"row":@"15",@"isImage":@"1",@"image":@"11.jpg",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 19 | @"娱乐":@{@"row":@"9",@"isImage":@"0",@"image":@"2.jpg",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 20 | @"要闻":@{@"row":@"2",@"isImage":@"1",@"image":@"3.jpg",@"type":@"推荐",@"cell":@[@"0",@"1"]}, 21 | @"体育":@{@"row":@"11",@"isImage":@"1",@"image":@"10.jpg",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 22 | @"汽车":@{@"row":@"7",@"isImage":@"1",@"image":@"4.jpg",@"type":@"推荐",@"cell":@[@"0",@"1",@"0",@"1",@"1",@"0",@"1"]}, 23 | @"图片":@{@"row":@"6",@"isImage":@"0",@"image":@"1.jpg",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"0"]}, 24 | @"科技":@{@"row":@"1",@"isImage":@"0",@"image":@"3.jpg",@"type":@"推荐",@"cell":@[@"1"]}, 25 | @"社会":@{@"row":@"14",@"isImage":@"1",@"image":@"8.png",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1"]}, 26 | @"读科学":@{@"row":@"10",@"isImage":@"0",@"image":@"6.png",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"0",@"1",@"0",@"1",@"1",@"0"]}, 27 | @"佛学":@{@"row":@"10",@"isImage":@"1",@"image":@"10.jpg",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 28 | @"军事":@{@"row":@"8",@"isImage":@"0",@"image":@"9.jpg",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0"]}, 29 | @"时尚":@{@"row":@"3",@"isImage":@"0",@"image":@"5.jpg",@"type":@"推荐",@"cell":@[@"1",@"1",@"0"]}, 30 | @"游戏":@{@"row":@"15",@"isImage":@"1",@"image":@"12.png",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 31 | @"房产":@{@"row":@"9",@"isImage":@"0",@"image":@"8.png",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 32 | @"数码":@{@"row":@"2",@"isImage":@"1",@"image":@"5.jpg",@"type":@"推荐",@"cell":@[@"1",@"0"]}, 33 | @"股票":@{@"row":@"11",@"isImage":@"1",@"image":@"4.jpg",@"type":@"推荐",@"cell":@[@"0",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 34 | @"国际":@{@"row":@"7",@"isImage":@"1",@"image":@"9.jpg",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0"]}, 35 | @"教育":@{@"row":@"6",@"isImage":@"0",@"image":@"7.jpg",@"type":@"推荐",@"cell":@[@"1",@"1",@"0",@"1",@"1",@"0",@"1"]}, 36 | @"电竞":@{@"row":@"1",@"isImage":@"0",@"image":@"5.jpg",@"type":@"推荐",@"cell":@[@"1"]}, 37 | @"电视剧":@{@"row":@"14",@"isImage":@"1",@"image":@"12.png",@"type":@"推荐",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 38 | @"重庆":@{@"row":@"10",@"isImage":@"1",@"image":@"7.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"1",@"0"]}, 39 | @"四川":@{@"row":@"8",@"isImage":@"0",@"image":@"6.png",@"type":@"地区",@"cell":@[@"0",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 40 | @"上海":@{@"row":@"3",@"isImage":@"0",@"image":@"6.png",@"type":@"地区",@"cell":@[@"1",@"1",@"0"]}, 41 | @"陕西":@{@"row":@"15",@"isImage":@"1",@"image":@"10.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 42 | @"山东":@{@"row":@"9",@"isImage":@"0",@"image":@"5.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"1"]}, 43 | @"浙江":@{@"row":@"2",@"isImage":@"1",@"image":@"1.jpg",@"type":@"地区",@"cell":@[@"0",@"1"]}, 44 | @"湖北":@{@"row":@"11",@"isImage":@"1",@"image":@"11.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0",@"0",@"1",@"0",@"1",@"1",@"0"]}, 45 | @"河南":@{@"row":@"7",@"isImage":@"1",@"image":@"10.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"0",@"1",@"1",@"0"]}, 46 | @"湖南":@{@"row":@"6",@"isImage":@"0",@"image":@"7.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"0",@"1",@"1",@"0"]}, 47 | @"福建":@{@"row":@"1",@"isImage":@"0",@"image":@"5.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"0",@"1",@"1",@"0",@"0",@"1",@"0",@"1",@"1",@"0",@"0",@"1",@"0",@"1",@"1",@"0",@"0",@"1",@"0",@"1",@"1",@"0"]}, 48 | @"江苏":@{@"row":@"14",@"isImage":@"1",@"image":@"1.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0",@"1",@"0",@"1",@"1",@"0"]}, 49 | @"北京":@{@"row":@"10",@"isImage":@"0",@"image":@"11.jpg",@"type":@"地区",@"cell":@[@"0",@"1",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0",@"0",@"1",@"1",@"0"]}}; 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/ImageCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // ImageCell.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ImageCell : UITableViewCell 12 | @property (strong, nonatomic) IBOutlet UILabel *topLabel; 13 | @property (strong, nonatomic) IBOutlet UILabel *bottomLabel1; 14 | @property (strong, nonatomic) IBOutlet UILabel *bottomLabel2; 15 | @property (strong, nonatomic) IBOutlet UIImageView *myImageVIew1; 16 | @property (strong, nonatomic) IBOutlet UIImageView *myImageView2; 17 | @property (strong, nonatomic) IBOutlet UIImageView *myImageView3; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/ImageCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // ImageCell.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "ImageCell.h" 10 | 11 | @implementation ImageCell 12 | 13 | - (void)awakeFromNib { 14 | [super awakeFromNib]; 15 | // Initialization code 16 | } 17 | 18 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 19 | [super setSelected:selected animated:animated]; 20 | 21 | // Configure the view for the selected state 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/ImageCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 49 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/MainViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MainViewController.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MainViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/MainViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MainViewController.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "MainViewController.h" 10 | #import "TitleView.h" 11 | #import "MyTableViewController.h" 12 | #import "ButtonsTableViewController.h" 13 | #import "DataModel.h" 14 | 15 | 16 | #define WIDTH [UIScreen mainScreen].bounds.size.width 17 | #define HEIGHT self.view.bounds.size.height 18 | #define LINEWIGTH ((WIDTH/5) - 10) 19 | #define TOPVIEWWIGTH self.topView.frame.size.width 20 | 21 | @interface MainViewController () 22 | //最上面的滚动视图 23 | @property (nonatomic, strong) TitleView* topView; 24 | //最下面的滚动视图 25 | @property (nonatomic, strong) UIScrollView* bottomScrollView; 26 | @property (nonatomic, strong) NSArray* titles; 27 | 28 | //数组保存滚动视图里面的控制器 29 | @property (nonatomic, strong) NSArray* views; 30 | //表视图的表格形式和行数 31 | //@property (nonatomic, strong) NSArray* cellStatus; 32 | //记录滚动视图的按钮位置 33 | @property (nonatomic, unsafe_unretained) NSInteger buttonIndex; 34 | //直接点击滚动视图中的按钮 和 滑动两种状态下 35 | //@property (nonatomic, unsafe_unretained) BOOL isScroll; 36 | 37 | @end 38 | 39 | @implementation MainViewController 40 | 41 | 42 | - (NSArray*)titles 43 | { 44 | if (!_titles) 45 | { 46 | _titles = @[@"广州",@"深圳",@"纪录片",@"财经",@"娱乐",@"要闻",@"体育",@"汽车",@"图片",@"科技",@"社会",@"读科学"]; 47 | } 48 | return _titles; 49 | } 50 | - (TitleView*)topView 51 | { 52 | if (!_topView) 53 | { 54 | _topView = [[TitleView alloc]initWithFrame:CGRectMake(2, 0, WIDTH - 50, 40)]; 55 | _topView.myScrollView.delegate = self; 56 | _topView.backgroundColor = [UIColor clearColor]; 57 | } 58 | return _topView; 59 | } 60 | - (void)viewDidLoad 61 | { 62 | [super viewDidLoad]; 63 | // 关闭系统自动偏移 64 | self.automaticallyAdjustsScrollViewInsets = NO; 65 | 66 | [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(buttonChange3:) name:@"buttonChange3" object:nil]; 67 | [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeArray:) name:@"ChangeArray" object:nil]; 68 | } 69 | - (void)viewDidAppear:(BOOL)animated 70 | { 71 | self.topView.buttonTitles = self.titles; 72 | self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)]; 73 | self.navigationItem.titleView = self.topView; 74 | [self.topView scrollView]; 75 | [self createScrollView]; 76 | [self showDurationForView]; 77 | } 78 | - (void)changeArray:(NSNotification*)notification 79 | { 80 | [self.topView removeScrollView]; 81 | self.titles = notification.userInfo[@"array"]; 82 | self.buttonIndex = [notification.userInfo[@"index"] integerValue]; 83 | [self createScrollView]; 84 | } 85 | //创建主滚动视图 86 | - (void)createScrollView 87 | { 88 | // self.imageTitles = @[@"1.jpg",@"2.jpg",@"3.jpg",@"4.jpg",@"5.jpg",@"6.png",@"7.jpg",@"8.png",@"9.jpg",@"10.jpg",@"11.jpg",@"12.png"]; 89 | self.bottomScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, WIDTH, HEIGHT - 64)]; 90 | self.bottomScrollView.scrollsToTop = NO; 91 | self.bottomScrollView.delegate = self; 92 | self.bottomScrollView.contentSize = CGSizeMake(self.titles.count * WIDTH, HEIGHT - 64); 93 | self.bottomScrollView.userInteractionEnabled = YES; 94 | self.bottomScrollView.bounces = NO; 95 | self.bottomScrollView.scrollEnabled = YES; 96 | self.bottomScrollView.pagingEnabled = YES; 97 | self.bottomScrollView.showsHorizontalScrollIndicator = NO; 98 | self.bottomScrollView.showsVerticalScrollIndicator = NO; 99 | NSMutableArray* array = [NSMutableArray array]; 100 | for (int i = 0; i 3) 140 | { 141 | self.topView.myScrollView.contentOffset = CGPointMake(LINEWIGTH * r + 5*(2*self.buttonIndex+1), 0); 142 | } 143 | else 144 | { 145 | self.topView.myScrollView.contentOffset = CGPointMake(0, 0); 146 | } 147 | } 148 | //点击最上面滚动视图 改变下面滚动视图的变化 149 | - (void)buttonChange3:(NSNotification*)notification 150 | { 151 | NSInteger index = [notification.userInfo[@"buttonTag"] integerValue]; 152 | self.buttonIndex = index; 153 | CGPoint point = self.bottomScrollView.contentOffset; 154 | point.x = index * WIDTH; 155 | self.bottomScrollView.contentOffset = point; 156 | for (MyTableViewController* vc in self.views) 157 | { 158 | if (vc.view.tag == index) 159 | { 160 | [vc.tableView reloadData]; 161 | } 162 | } 163 | } 164 | #pragma mark - UIScrollViewDelegate 165 | 166 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView 167 | { 168 | if (scrollView == self.bottomScrollView) 169 | { 170 | CGPoint point = self.bottomScrollView.contentOffset; 171 | //取比率 172 | CGFloat r = point.x/WIDTH; 173 | //取整数 174 | NSInteger n = (NSInteger)point.x/WIDTH; 175 | self.buttonIndex = n; 176 | NSLog(@"大滚动视图滚动的距离 = %ld",n); 177 | //当滚动距离大于0 178 | if (point.x > 0) 179 | { 180 | [UIView animateWithDuration:0.3 animations:^{ 181 | self.topView.bottomView.frame = CGRectMake(LINEWIGTH * r + 5*(2*n+1), self.topView.myScrollView.frame.size.height - 3, LINEWIGTH, 3); 182 | // NSLog(@"self.topView.bottomView.frame = %f",self.topView.bottomView.frame.origin.x); 183 | //当最上方的滚动视图滚动到第5个按钮的时候,需要把最上方的滚动视图向右滚动一段距离,以便第五个按钮看得见 184 | 185 | //正在拖拽的时候 186 | if (self.bottomScrollView.dragging) 187 | { 188 | if (n > 3) 189 | { 190 | self.topView.myScrollView.contentOffset = CGPointMake(LINEWIGTH * r + 5*(2*n+1), 0); 191 | } 192 | else 193 | { 194 | self.topView.myScrollView.contentOffset = CGPointMake(0, 0); 195 | } 196 | } 197 | for (UIButton* button in self.topView.allButtons) 198 | { 199 | if (button.tag == n) 200 | { 201 | [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 202 | } 203 | else 204 | { 205 | [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; 206 | } 207 | } 208 | }]; 209 | } 210 | } 211 | } 212 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 213 | 214 | { 215 | 216 | // Return YES for supported orientations 217 | 218 | return (interfaceOrientation == UIInterfaceOrientationPortrait); 219 | 220 | } 221 | 222 | @end 223 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/MyCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // MyCell.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MyCell : UITableViewCell 12 | @property (strong, nonatomic) IBOutlet UILabel *topLabel; 13 | @property (strong, nonatomic) IBOutlet UILabel *bottomLabel1; 14 | @property (strong, nonatomic) IBOutlet UILabel *bottomLabel2; 15 | @property (strong, nonatomic) IBOutlet UIImageView *myImageView; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/MyCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // MyCell.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "MyCell.h" 10 | 11 | @implementation MyCell 12 | 13 | - (void)awakeFromNib { 14 | [super awakeFromNib]; 15 | // Initialization code 16 | } 17 | 18 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 19 | [super setSelected:selected animated:animated]; 20 | 21 | // Configure the view for the selected state 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/MyCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | 37 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/MyTableViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MyTableViewController.h 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MyTableViewController : UITableViewController 12 | 13 | @property (nonatomic, strong) NSString* imageTitle; 14 | //测试行数 15 | @property (nonatomic, unsafe_unretained) NSInteger test; 16 | 17 | @property (nonatomic, unsafe_unretained) BOOL isImage; 18 | //按钮标题 19 | @property (nonatomic, strong) NSString* myTitle; 20 | 21 | @property (nonatomic, strong) NSArray* scrollViewImageTitles; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/MyTableViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MyTableViewController.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "MyTableViewController.h" 10 | #import "MyCell.h" 11 | #import "ImageCell.h" 12 | #import "DataModel.h" 13 | 14 | @interface MyTableViewController () 15 | 16 | #define SCROLLVIEWWIDHT ([UIScreen mainScreen].bounds.size.width - 20) 17 | #define SCROLLVIEWHEIGHT self.headerScrollView.frame.size.height 18 | 19 | @property (strong, nonatomic) IBOutlet UIImageView *myImageView; 20 | @property (strong, nonatomic) IBOutlet UIScrollView *headerScrollView; 21 | @property (strong, nonatomic) IBOutlet UIPageControl *firstPageControl; 22 | 23 | @end 24 | 25 | @implementation MyTableViewController 26 | 27 | - (void)viewDidLoad 28 | { 29 | [super viewDidLoad]; 30 | 31 | [self.tableView registerNib:[UINib nibWithNibName:@"MyCell" bundle:nil] forCellReuseIdentifier:@"cell1"]; 32 | [self.tableView registerNib:[UINib nibWithNibName:@"ImageCell" bundle:nil] forCellReuseIdentifier:@"cell2"]; 33 | } 34 | 35 | - (void)createScrollView 36 | { 37 | self.headerScrollView.contentSize = CGSizeMake(SCROLLVIEWWIDHT * self.scrollViewImageTitles.count, SCROLLVIEWHEIGHT); 38 | for (int i = 0; i < self.scrollViewImageTitles.count; i++) 39 | { 40 | UIButton* button = [[UIButton alloc]init]; 41 | button.tag = i; 42 | button.frame = CGRectMake(SCROLLVIEWWIDHT * i, 0, SCROLLVIEWWIDHT, SCROLLVIEWHEIGHT); 43 | [button setTitle:@"" forState:UIControlStateNormal]; 44 | [button setBackgroundImage:[UIImage imageNamed:self.scrollViewImageTitles[i]] forState:UIControlStateNormal]; 45 | [button addTarget:self action:@selector(pushVC:) forControlEvents:UIControlEventTouchUpInside]; 46 | [self.headerScrollView addSubview:button]; 47 | } 48 | self.firstPageControl.numberOfPages = self.scrollViewImageTitles.count; 49 | self.firstPageControl.userInteractionEnabled = YES; 50 | } 51 | - (void)viewDidAppear:(BOOL)animated 52 | { 53 | if (self.isImage) 54 | { 55 | //头视图 是一张图片 56 | 57 | [self.firstPageControl setHidden:YES]; 58 | [self.myImageView setHidden:NO]; 59 | [self.headerScrollView setHidden:YES]; 60 | } 61 | else 62 | { 63 | //头视图 是一个滚动视图 64 | [self.firstPageControl setHidden:NO]; 65 | [self.myImageView setHidden:YES]; 66 | [self.headerScrollView setHidden:NO]; 67 | [self createScrollView]; 68 | } 69 | NSLog(@"图片名称 = %@",self.imageTitle); 70 | self.myImageView.image = [UIImage imageNamed:self.imageTitle]; 71 | } 72 | 73 | - (void)pushVC:(UIButton*)sender 74 | { 75 | NSLog(@"滚动视图按钮的tag值%ld",sender.tag); 76 | } 77 | #pragma mark - UIScrollViewDelegate 78 | 79 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView 80 | { 81 | if (scrollView == self.headerScrollView) 82 | { 83 | CGPoint point = scrollView.contentOffset; 84 | self.firstPageControl.currentPage = (NSInteger)point.x/SCROLLVIEWHEIGHT; 85 | } 86 | } 87 | 88 | #pragma mark - Table view data source 89 | 90 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 91 | { 92 | return 1; 93 | } 94 | 95 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 96 | { 97 | return self.test; 98 | } 99 | - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 100 | { 101 | return 1.0; 102 | } 103 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 104 | { 105 | return [[DataModel getNewsArray][self.myTitle][@"cell"][indexPath.row] boolValue] ? 140.0 : 100.0; 106 | } 107 | 108 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 109 | { 110 | if ([[DataModel getNewsArray][self.myTitle][@"cell"][indexPath.row] boolValue]) 111 | { 112 | ImageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell2" forIndexPath:indexPath]; 113 | cell.myImageVIew1.image = [UIImage imageNamed:self.imageTitle]; 114 | cell.myImageView2.image = [UIImage imageNamed:self.imageTitle]; 115 | cell.myImageView3.image = [UIImage imageNamed:self.imageTitle]; 116 | return cell; 117 | } 118 | else 119 | { 120 | MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1" forIndexPath:indexPath]; 121 | cell.myImageView.image = [UIImage imageNamed:self.imageTitle]; 122 | return cell; 123 | } 124 | } 125 | 126 | @end 127 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/MyTableViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 33 | 34 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/TRButton.h: -------------------------------------------------------------------------------- 1 | // 2 | // TRButton.h 3 | // 拖拽排列按钮 4 | // 5 | // Created by leiyu on 15/8/27. 6 | // Copyright (c) 2015年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | typedef void (^DisplayComletionBlock)(void); 11 | typedef void (^DisplayCloseBlock)(UIView* displayView,CFTimeInterval duration); 12 | typedef void (^DisplayOpenBlock)(UIView* displayView,CFTimeInterval duration); 13 | 14 | @class TRButton; 15 | @protocol TRButtonDelegate 16 | 17 | - (void) dragButton:(TRButton*)button buttons:(NSArray*)buttons; 18 | 19 | @end 20 | 21 | @interface TRButton : UIButton 22 | @property (nonatomic ,strong) id delegate; 23 | //存放需要拖拽的按钮数组 24 | @property (nonatomic ,strong) NSMutableArray* btnArray; 25 | //按钮正在被拖拽移动时的背景颜色 26 | @property (nonatomic ,strong) UIColor* color; 27 | //一排按钮的个数,如果使用openDisplayView方法,lineCount不能为空 28 | @property (nonatomic ,unsafe_unretained) NSUInteger lineCount; 29 | 30 | 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/TitleView.h: -------------------------------------------------------------------------------- 1 | // 2 | // TitleView.h 3 | // 华康通 4 | // 5 | // Created by 雷雨 on 16/4/19. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TitleView : UIView 12 | 13 | @property (nonatomic, strong) UIScrollView* myScrollView; 14 | @property (nonatomic, strong) NSArray* buttonTitles; 15 | @property (nonatomic, strong) NSMutableArray* allButtons; 16 | @property (nonatomic, strong) UIView* bottomView; 17 | 18 | - (void)scrollView; 19 | - (void)removeScrollView; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/TitleView.m: -------------------------------------------------------------------------------- 1 | // 2 | // TitleView.m 3 | // 华康通 4 | // 5 | // Created by 雷雨 on 16/4/19. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "TitleView.h" 10 | 11 | #define SCREENWIDTH [UIScreen mainScreen].bounds.size.width 12 | 13 | @implementation TitleView 14 | 15 | 16 | - (NSMutableArray*)allButtons 17 | { 18 | if (!_allButtons) 19 | { 20 | _allButtons = [NSMutableArray array]; 21 | } 22 | return _allButtons; 23 | } 24 | 25 | //更新表格 26 | - (void)changeData:(UIButton*)sender 27 | { 28 | for (UIButton* button in self.allButtons) 29 | { 30 | if (button.tag == sender.tag) 31 | { 32 | [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 33 | } 34 | else 35 | { 36 | [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; 37 | } 38 | [self animationForViewWithButton:sender withTag:sender.tag]; 39 | } 40 | [[NSNotificationCenter defaultCenter]postNotificationName:@"buttonChange3" object:self userInfo:@{@"buttonTag":[NSString stringWithFormat:@"%ld",(long)sender.tag],@"buttonArray":self.allButtons}]; 41 | } 42 | - (void)scrollView 43 | { 44 | self.myScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; 45 | 46 | self.myScrollView.contentSize = CGSizeMake(self.buttonTitles.count * SCREENWIDTH / 5, self.frame.size.height); 47 | self.myScrollView.userInteractionEnabled = YES; 48 | self.myScrollView.bounces = YES; 49 | self.myScrollView.scrollEnabled = YES; 50 | self.myScrollView.pagingEnabled = NO; 51 | self.myScrollView.showsHorizontalScrollIndicator = NO; 52 | self.myScrollView.showsVerticalScrollIndicator = NO; 53 | for (int i = 0; i 10 | 11 | @interface UIColor (SelfColor) 12 | 13 | + (UIColor *)getColor:(NSString *)hexColor; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/UIColor+SelfColor.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+SelfColor.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/7/4. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import "UIColor+SelfColor.h" 10 | 11 | @implementation UIColor (SelfColor) 12 | 13 | + (UIColor *)getColor:(NSString *)hexColor 14 | { 15 | unsigned int red,green,blue; 16 | NSRange range; 17 | range.length = 2; 18 | 19 | range.location = 0; 20 | [[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&red]; 21 | 22 | range.location = 2; 23 | [[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&green]; 24 | 25 | range.location = 4; 26 | [[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&blue]; 27 | 28 | return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green / 255.0f) blue:(float)(blue / 255.0f) alpha:1.0f]; 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 两个滚动视图做界面 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面Tests/_________Tests.m: -------------------------------------------------------------------------------- 1 | // 2 | // _________Tests.m 3 | // 两个滚动视图做界面Tests 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface _________Tests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation _________Tests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面UITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /两个滚动视图实现腾讯新闻的效果/两个滚动视图做界面/两个滚动视图做界面UITests/_________UITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // _________UITests.m 3 | // 两个滚动视图做界面UITests 4 | // 5 | // Created by leiyu on 16/6/27. 6 | // Copyright © 2016年 华康集团. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface _________UITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation _________UITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | --------------------------------------------------------------------------------