如何在iOS上实现苹果电脑最小化窗口时的“神奇效果”(即吸入吸出效果在iPhone上的实现)
生活随笔
收集整理的這篇文章主要介紹了
如何在iOS上实现苹果电脑最小化窗口时的“神奇效果”(即吸入吸出效果在iPhone上的实现)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
先看一下效果
1.首先創(chuàng)建一個(gè)新工程,結(jié)構(gòu)是TabbarViewController+UIViewController*4
@interface AppDelegate ()<UITabBarControllerDelegate> {UITabBarController *tabBarController;NSMutableArray *isInArray; // 標(biāo)記動(dòng)畫方向UIViewController *controller; //一個(gè)全局VC }- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {////初始化window設(shè)置其背景圖//self.window = [[UIWindow alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH_NEW, SCREEN_HEIGHT_NEW)];UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"b%d",5]]];imageView.frame = self.window.frame;[self.window addSubview:imageView];////array:存放4個(gè)透明VC(為了正常顯示系統(tǒng)的TabBar和其點(diǎn)擊事件)。第一個(gè)VC默認(rèn)設(shè)置微信截圖//NSMutableArray *array = [[NSMutableArray alloc]initWithCapacity:4];NSArray *titleArray = @[@"微信",@"通訊錄",@"發(fā)現(xiàn)",@"我"];for(int i = 0 ; i < 4 ; i ++){UIViewController *controller_ = [[UIViewController alloc]init];[array addObject:controller_];UITabBarItem *item = [[UITabBarItem alloc]initWithTitle:titleArray[i] image:[UIImage imageNamed:[NSString stringWithFormat:@"%d",i+1]] tag:i];controller_.tabBarItem = item;if (i == 0) {UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"b%d",i+1]]];imageView.frame = self.window.frame;[controller_.view addSubview:imageView];}}tabBarController = [[UITabBarController alloc]init];tabBarController.viewControllers = array;tabBarController.delegate = self;self.window.rootViewController = tabBarController;[self.window makeKeyAndVisible];////全局VC,展示不同截圖//controller = [[UIViewController alloc]init];////動(dòng)畫方向//isInArray = @[[NSNumber numberWithBool:NO],[NSNumber numberWithBool:YES],[NSNumber numberWithBool:YES],[NSNumber numberWithBool:YES]].mutableCopy;return YES; }
2 實(shí)現(xiàn)UITabBarControllerDelegate -(void)tabBarController:(UITabBarController *)tabBarControllerLocal didSelectViewController:(UIViewController *)viewController{NSLog(@"%lu",(unsigned long)tabBarController.selectedIndex);////tabBarItem點(diǎn)擊后 就把默認(rèn)圖移除//[tabBarController.viewControllers[0].view removeAllSubviews];////設(shè)置對(duì)應(yīng)截圖//UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"b%lu",tabBarController.selectedIndex+1]]];imageView.frame = self.window.frame;[controller.view addSubview:imageView];[tabBarController.view insertSubview:controller.view belowSubview:tabBarController.tabBar];////開始動(dòng)畫//[self genieToRect:CGRectMake(0, 0, 0, 0) edge:BCRectEdgeTop ];}3 實(shí)現(xiàn)動(dòng)畫方法 。從github上下載UIView+Genie這個(gè)開源代碼,然后引入U(xiǎn)IView+Genie。地址https://github.com/Ciechan/BCGenieEffect/
- (void) genieToRect: ( CGRect)rect2 edge: (BCRectEdge) edge {dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{////isin = NO執(zhí)行的是向下回收的動(dòng)畫 一個(gè)頁面下來 其他的應(yīng)該都下去//////不同的起始位置//CGRect rect = CGRectMake(SCREEN_WIDTH_NEW/4* tabBarController.selectedIndex, SCREEN_HEIGHT_NEW +100, SCREEN_WIDTH_NEW / 5, 20);UIView *tranView = controller.view;BOOL isin = [isInArray[tabBarController.selectedIndex] boolValue];if (isin == NO) {////向下//for (int i = 0; i < isInArray.count; i ++) {if (i != tabBarController.selectedIndex) {[isInArray replaceObjectAtIndex:i withObject:[NSNumber numberWithBool:YES]];tabBarController.viewControllers[i].view.frame = CGRectMake(SCREEN_WIDTH_NEW/4* i, SCREEN_HEIGHT_NEW +20, SCREEN_WIDTH_NEW/5, 20);;}}}else{////向上//for (int i = 0; i < isInArray.count; i ++) {if (i != tabBarController.selectedIndex) {[isInArray replaceObjectAtIndex:i withObject:[NSNumber numberWithBool:YES]];tabBarController.viewControllers[i].view.frame = CGRectMake(SCREEN_WIDTH_NEW/4* i, SCREEN_HEIGHT_NEW +20, SCREEN_WIDTH_NEW/5, 20);;}}}NSTimeInterval duration = 0.5;tabBarController.tabBar.userInteractionEnabled = NO;CGRect endRect = rect;if (isin) {[tranView genieOutTransitionWithDuration:duration startRect:endRect startEdge:edge completion:^{BOOL isInLocal = [isInArray[tabBarController.selectedIndex] boolValue];[isInArray replaceObjectAtIndex:tabBarController.selectedIndex withObject:[NSNumber numberWithBool:!isInLocal]];tabBarController.tabBar.userInteractionEnabled = YES;}];} else {NSLog(@"xia");[tranView genieInTransitionWithDuration:duration destinationRect:endRect destinationEdge:edge completion:^{BOOL isInLocal = [isInArray[tabBarController.selectedIndex] boolValue];[isInArray replaceObjectAtIndex:tabBarController.selectedIndex withObject:[NSNumber numberWithBool:!isInLocal]];tabBarController.tabBar.userInteractionEnabled = YES;}];}}); }
demo 下載 http://download.csdn.net/detail/qq_15509071/9824864
總結(jié)
以上是生活随笔為你收集整理的如何在iOS上实现苹果电脑最小化窗口时的“神奇效果”(即吸入吸出效果在iPhone上的实现)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IBM i 7.2 –超越一切
- 下一篇: 数据分析/AI在校园网建设中的应用