iOS项目实践之时光电影(一)
1. 無限互聯(lián)熊彪的視頻-時光電影項目
1.1 需求文檔 - 產(chǎn)品部門產(chǎn)生
1.2 架構(gòu)設(shè)計-mvc,緩存策略,可擴(kuò)展,廣告位預(yù)留,更新預(yù)留
1.3 業(yè)務(wù)邏輯分析-哪些人用,做什么,用戶習(xí)慣收集
? ? ? 業(yè)務(wù)邏輯設(shè)計-類,接口,類關(guān)系
1.4 界面設(shè)計 - 美工產(chǎn)生
1.5 用戶交互-用戶體驗師ue
1.6 與服務(wù)器交互-http ? : 開發(fā)容易,數(shù)據(jù)包大
? ? ? ? ? ? ? ? ? ? ? ? ? ?socket ?:數(shù)據(jù)包小,適合實時交互如微信
? ? ? 數(shù)據(jù)交換格式-JSON :使用方便,都用這個
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? xml : SAX(邊load邊解析), DOM(一下load到內(nèi)存)
1.7 接口定義-這是重點,與服務(wù)器的接口定義
1.8 開發(fā)規(guī)范 - 駝峰命名法
2. 項目架構(gòu)
2.1 結(jié)構(gòu)圖
2.2 搭建項目框架
新建一個singleview,去掉viewcontroller
2.2.1 添加圖片,工具類
注意添加圖片時選擇create group,不然圖片讀取不到,搞了多久才發(fā)現(xiàn)圖片沒讀出來。
2.2.2 新建tab的幾個文件
1)建立mainviewcontroller
2)AppDelegate.m中加入
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// Override point for customization after application launch.self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;self.window.backgroundColor = [UIColor redColor];[self.window makeKeyAndVisible];MainViewController *mainCtrl = [[MainViewController alloc] init];[self.window setRootViewController:mainCtrl];return YES; }
3)prefix header
build_setting里面設(shè)置prefix header,這樣就可以把需要的頭文件加入了。
4)mainviewcontroller.h
@interface MainViewController : UITabBarController {@private//自定義tabbar視圖UIView *_tabBarView;//上次選中的buttonUIButton *_lastButton; } @endmainviewcontroller.m
// // MainViewController.m // SGMovie // // Created by robin on 16/2/27. // Copyright ? 2016年 robin. All rights reserved. //#import "MainViewController.h" #import "WXHLGlobalUICommon.h"#import "HomeViewController.h" #import "NewsController.h" #import "MovieRatingViewController.h" #import "CinemaViewController.h"@interface MainViewController () - (void) _initImageView; // _ 表示我們自己定義的方法 - (void) _initWithViewController;@end@implementation MainViewController- (id) initWithNibName : (NSString*) nibNameOrNil bundle: (NSBundle*)nibBundleOrNil {self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];if (self ) {// 隱藏控制器的tabbarself.tabBar.hidden = YES;}return self; }- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.[self _initImageView];[self _initWithViewController];//UIView *transitionView = [[self.view subviews] objectAtIndex:0];//NSLog(@"transitionview:%@", transitionView);//transitionview:<UITransitionView: 0x7fa9e961f6b0; frame = (0 0; 320 568); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x7fa9e961faf0>>for (UIView *subView in self.view.subviews){if ([subView isKindOfClass:NSClassFromString(@"UITransitionView")]) {// 重新調(diào)整UITabbarViewController根視圖的大小subView.frame = CGRectMake(subView.frame.origin.x, subView.frame.origin.y, subView.frame.size.width, IPHONE_HEIGHT);}} }- (void) _initWithViewController {HomeViewController *homeCtrl = [[HomeViewController alloc] init];NewsController *newsCtrl = [[NewsController alloc] init];MovieRatingViewController *ratingCtrl = [[MovieRatingViewController alloc] init];CinemaViewController *cinemaCtrl = [[CinemaViewController alloc] init];UINavigationController *homeNav = [[UINavigationController alloc] initWithRootViewController:homeCtrl];UINavigationController *newsNav = [[UINavigationController alloc] initWithRootViewController:newsCtrl];UINavigationController *ratingNav = [[UINavigationController alloc] initWithRootViewController:ratingCtrl];UINavigationController *cinemaNav = [[UINavigationController alloc] initWithRootViewController:cinemaCtrl];NSArray *ctrls = [NSArray arrayWithObjects:homeNav, newsNav, ratingNav, cinemaNav,nil];self.viewControllers = ctrls; }- (void) _initImageView {// 獲取整個物理屏幕大小CGRect frame = WXHLApplicationBounds();// 創(chuàng)建tabbar_tabBarView = [[UIView alloc] initWithFrame:CGRectMake(frame.origin.x, frame.size.height-TABBAR_HEIGHT, frame.size.width, TABBAR_HEIGHT)];_tabBarView.backgroundColor = [UIColor blueColor];// 創(chuàng)建首頁buttonUIButton *homeButton = [UIButton buttonWithType:UIButtonTypeCustom];[homeButton setFrame:CGRectMake(frame.origin.x, frame.origin.y, TABBAR_TAP_BUTTON_WIDTH, TABBAR_HEIGHT)];[homeButton setImage:[UIImage imageNamed:TABBAR_TAP_HOMEBUTTON_IMAGE] forState:UIControlStateNormal];[homeButton setImage:[UIImage imageNamed:TABBAR_TAP_HOMEBUTTON_SELECTED_IMAGE] forState:UIControlStateHighlighted];[homeButton setTag:0];homeButton.selected = YES;_lastButton = homeButton;[homeButton addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];[_tabBarView addSubview:homeButton];// 創(chuàng)建新聞buttonUIButton *newsButton = [UIButton buttonWithType:UIButtonTypeCustom];[newsButton setFrame:CGRectMake(frame.origin.x+TABBAR_TAP_BUTTON_WIDTH*1, frame.origin.y, TABBAR_TAP_BUTTON_WIDTH, TABBAR_HEIGHT)];[newsButton setImage:[UIImage imageNamed:TABBAR_TAP_NEWSBUTTON_IMAGE] forState:UIControlStateNormal];[newsButton setImage:[UIImage imageNamed:TABBAR_TAP_NEWSBUTTON_SELECTED_IMAGE] forState:UIControlStateHighlighted];[newsButton setTag:2];[newsButton addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];[_tabBarView addSubview:newsButton];// 添加到當(dāng)前控制器到view上[self.view addSubview:_tabBarView];// 創(chuàng)建影評buttonUIButton *ratingButton = [UIButton buttonWithType:UIButtonTypeCustom];[ratingButton setFrame:CGRectMake(frame.origin.x+TABBAR_TAP_BUTTON_WIDTH*2, frame.origin.y, TABBAR_TAP_BUTTON_WIDTH, TABBAR_HEIGHT)];[ratingButton setImage:[UIImage imageNamed:TABBAR_TAP_RATINGBUTTON_IMAGE] forState:UIControlStateNormal];[ratingButton setImage:[UIImage imageNamed:TABBAR_TAP_RATINGBUTTON_SELECTED_IMAGE] forState:UIControlStateHighlighted];[ratingButton setTag:2];[ratingButton addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];[_tabBarView addSubview:ratingButton];// 創(chuàng)建電影院buttonUIButton *cinemaButton = [UIButton buttonWithType:UIButtonTypeCustom];[cinemaButton setFrame:CGRectMake(frame.origin.x+TABBAR_TAP_BUTTON_WIDTH*3, frame.origin.y, TABBAR_TAP_BUTTON_WIDTH, TABBAR_HEIGHT)];[cinemaButton setImage:[UIImage imageNamed:TABBAR_TAP_CINEMABUTTON_IMAGE] forState:UIControlStateNormal];[cinemaButton setImage:[UIImage imageNamed:TABBAR_TAP_CINEMABUTTON_SELECTED_IMAGE] forState:UIControlStateHighlighted];[cinemaButton setTag:3];[cinemaButton addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];[_tabBarView addSubview:cinemaButton];// 創(chuàng)建更多buttonUIButton *moreButton = [UIButton buttonWithType:UIButtonTypeCustom];[moreButton setFrame:CGRectMake(frame.origin.x+TABBAR_TAP_BUTTON_WIDTH*4, frame.origin.y, TABBAR_TAP_BUTTON_WIDTH, TABBAR_HEIGHT)];[moreButton setImage:[UIImage imageNamed:TABBAR_TAP_MOREBUTTON_IMAGE] forState:UIControlStateNormal];[moreButton setImage:[UIImage imageNamed:TABBAR_TAP_MOREBUTTON_SELECTED_IMAGE] forState:UIControlStateHighlighted];[moreButton setTag:4];[moreButton addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];[_tabBarView addSubview:moreButton];}- (void)tapAction:(UIButton*)button {if (_lastButton != button){_lastButton.selected = NO;}_lastButton = button;button.selected = YES;self.selectedIndex = button.tag;}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated. }/* #pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {// Get the new view controller using [segue destinationViewController].// Pass the selected object to the new view controller. } */@end5)xcode7.2 不能建立新的空工程,只能先建一個sigleview,然后把main.storyboard等刪了,然后把plist的相關(guān)項刪了,然后在app delegate里面加上面那幾行代碼。
下面就是tabbar的效果了,哈哈!
mac上面加圖片怎么這么大,有沒有知道怎么變小點???
總結(jié)
以上是生活随笔為你收集整理的iOS项目实践之时光电影(一)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Idea 支持Windows7的版本
- 下一篇: 《Web实战指南》00:万维网之父:蒂姆