1. 无限互联熊彪的视频-时光电影项目
1.1 需求文档 - 产品部门产生
1.2 架构设计-mvc,缓存策略,可扩展,广告位预留,更新预留
1.3 业务逻辑分析-哪些人用,做什么,用户习惯收集
业务逻辑设计-类,接口,类关系
1.4 界面设计 - 美工产生
1.5 用户交互-用户体验师ue
1.6 与服务器交互-http : 开发容易,数据包大
socket :数据包小,适合实时交互如微信
数据交换格式-JSON :使用方便,都用这个
xml : SAX(边load边解析), DOM(一下load到内存)
1.7 接口定义-这是重点,与服务器的接口定义
1.8 开发规范 - 驼峰命名法
2. 项目架构
2.1 结构图
2.2 搭建项目框架
新建一个singleview,去掉viewcontroller
2.2.1 添加图片,工具类
注意添加图片时选择create group,不然图片读取不到,搞了多久才发现图片没读出来。
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里面设置prefix header,这样就可以把需要的头文件加入了。
4)mainviewcontroller.h
@interface MainViewController : UITabBarController
{
@private
//自定义tabbar视图
UIView *_tabBarView;
//上次选中的button
UIButton *_lastButton;
}
@end
mainviewcontroller.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 ) {
// 隐藏控制器的tabbar
self.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")]) {
// 重新调整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();
// 创建tabbar
_tabBarView = [[UIView alloc] initWithFrame:CGRectMake(frame.origin.x, frame.size.height-TABBAR_HEIGHT, frame.size.width, TABBAR_HEIGHT)];
_tabBarView.backgroundColor = [UIColor blueColor];
// 创建首页button
UIButton *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];
// 创建新闻button
UIButton *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];
// 添加到当前控制器到view上
[self.view addSubview:_tabBarView];
// 创建影评button
UIButton *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];
// 创建电影院button
UIButton *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];
// 创建更多button
UIButton *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.
}
*/
@end
5)xcode7.2 不能建立新的空工程,只能先建一个sigleview,然后把main.storyboard等删了,然后把plist的相关项删了,然后在app delegate里面加上面那几行代码。
下面就是tabbar的效果了,哈哈!
mac上面加图片怎么这么大,有没有知道怎么变小点???