標籤:
今天劉國斌老師教了實戰的一個demo,仿寫音樂播放器
// 1、 如果在viewcontroller裡跳轉到別的頁面裡,另一個viewcontroller是storyboard拖出來的,初始化頁面需要用self.stroy 再調用方法,instantiateViewControllerWithIdentifier
// 2、 但是如果在其他的頁面不是viewcontroller裡再跳轉到另一個頁面,那個頁面也是用stroyboard拖出來的,那麼就要用 UIStoryboard 通過自己的mainstoryboard標記“Main”先建立一個對象,在用這個對象去初始化另一個頁面
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
// 宏定義自動擷取的螢幕的尺寸
#define SCREEN_SIZE [UIScreen mainScreen].bounds.size
// 功能實現從第一個頁面跳轉到tabbarcontroller
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIScrollView *sc=[[UIScrollView alloc]initWithFrame:[UIScreen mainScreen].bounds];
sc.pagingEnabled=YES;
for (int i=0; i<5; i++) {
UIImageView *iv=[[UIImageViewalloc]initWithFrame:CGRectMake(i*SCREEN_SIZE.width, 0, SCREEN_SIZE.width, SCREEN_SIZE.height)];
iv.image=[UIImage imageNamed:[NSStringstringWithFormat:@"Welcome_3.0_%d.jpg",i+1]];
[sc addSubview:iv];
}
CGRect bnFram=CGRectMake(0, 0, SCREEN_SIZE.width, SCREEN_SIZE.height);
UIButton *bn=[[UIButton alloc]initWithFrame:bnFram];
[bn addTarget:self action:@selector(moo) forControlEvents:UIControlEventTouchUpInside];
[sc addSubview:bn];
sc.delegate=self;
// 考慮到螢幕尺寸適配問題,這裡的內容contentSize取動態
sc.contentSize=CGSizeMake(5*SCREEN_SIZE.width, 667);
[self.view addSubview:sc];
}
-(void)moo{
tabONe *ta1=[tabONe new];
ta1.view.backgroundColor=[UIColor colorWithRed:.5 green:.5 blue:.6 alpha:.7];
[email protected]"原諒我這一生放蕩不羈";
UINavigationController *nv1=[[UINavigationControlleralloc]initWithRootViewController:ta1];
[email protected]"我的音樂";
nv1.tabBarItem.image=[UIImage imageNamed:@"tabbar_item_my_music.png"];
tabTwo *ta2=[tabTwo new];
ta2.view.backgroundColor=[UIColor redColor];
[email protected]"辣麼屌";
UINavigationController *nv2=[[UINavigationControlleralloc]initWithRootViewController:ta2];
[email protected]"網路";
nv2.tabBarItem.image=[UIImage imageNamed:@"tabbar_item_selected"];
tabThree *ta3=[tabThree new];
[email protected]"沒文化,讀書";
ta3.view.backgroundColor=[UIColor blueColor];
UINavigationController *nv3=[[UINavigationControlleralloc]initWithRootViewController:ta3];
[email protected]"本地";
nv3.tabBarItem.image=[UIImage imageNamed:@"tabbar_item_store_selected.png"];
tabFour *ta4=[tabFour new];
[email protected]"多麼痛的領悟";
ta4.view.backgroundColor=[UIColor greenColor];
UINavigationController *nv4=[[UINavigationControlleralloc]initWithRootViewController:ta4];
[email protected]"更多";
nv4.tabBarItem.image=[UIImage imageNamed:@"tabbar_item_more.png"];
UITabBarController *tabBar=[[UITabBarController alloc]init];
[email protected][nv1,nv2,nv3,nv4];
[self presentViewController:tabBar animated:YES completion:nil];
}
藍懿IOS實戰音樂播放器