如何在iOS上实现苹果电脑最小化窗口时的“神奇效果”(即吸入吸出效果在iPhone上的实现)
来源:互联网 发布:网络应急预案 编辑:程序博客网 时间:2024/04/29 10:24
先看一下效果
1.首先创建一个新工程,结构是TabbarViewController+UIViewController*4
@interface AppDelegate ()<UITabBarControllerDelegate>{ UITabBarController *tabBarController; NSMutableArray *isInArray; // 标记动画方向 UIViewController *controller; //一个全局VC}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // //初始化window设置其背景图 // 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个透明VC(为了正常显示系统的TabBar和其点击事件)。第一个VC默认设置微信截图 // NSMutableArray *array = [[NSMutableArray alloc]initWithCapacity:4]; NSArray *titleArray = @[@"微信",@"通讯录",@"发现",@"我"]; 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]; // //动画方向 // isInArray = @[[NSNumber numberWithBool:NO], [NSNumber numberWithBool:YES], [NSNumber numberWithBool:YES], [NSNumber numberWithBool:YES]].mutableCopy; return YES;}
2 实现UITabBarControllerDelegate
-(void)tabBarController:(UITabBarController *)tabBarControllerLocal didSelectViewController:(UIViewController *)viewController{ NSLog(@"%lu",(unsigned long)tabBarController.selectedIndex); // //tabBarItem点击后 就把默认图移除 // [tabBarController.viewControllers[0].view removeAllSubviews]; // //设置对应截图 // 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]; // //开始动画 // [self genieToRect:CGRectMake(0, 0, 0, 0) edge:BCRectEdgeTop ]; }3 实现动画方法 。从github上下载UIView+Genie这个开源代码,然后引入UIView+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执行的是向下回收的动画 一个页面下来 其他的应该都下去 // // //不同的起始位置 // 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
0 0
- 如何在iOS上实现苹果电脑最小化窗口时的“神奇效果”(即吸入吸出效果在iPhone上的实现)
- 如何在android上实现IPhone的按钮滑动效果
- 如何在5.0上实现button的Ripple(水波效果)
- 在WM6.1上实现可以最小化的模式窗口
- iOS特效之仿Mac窗口最小化的神奇效果
- iphone上自定义状态栏效果的实现
- 如何在 iPhone 中实现图片的毛玻璃效果
- iOS—在tableView上实现始终在屏幕底部有一个button的效果
- 在 iOS 5+ 上实现了 iOS 7 的 UISwitch 效果:KLSwitch
- IOS 上图书翻页效果的实现
- iOS上实现Android的Toast效果
- 实现鼠标移在图片上出现渐现的效果
- 如果在BlackBerry上实现动态分页的效果
- 在Android手机上实现阅读器的翻页效果
- 在Android手机上实现阅读器的翻页效果
- 在Android手机上实现阅读器的翻页效果
- 在Android手机上实现阅读器的翻页效果
- 在Android手机上实现阅读器的翻页效果
- android-ndk-r14b 编译renderscript的BUG(Window平台下)
- java 消息机制 ActiveMQ入门实例
- IMWeb训练营作业——select
- 架构设计:系统存储(30)——分布式文件系统Ceph(RADOS结构)
- SQL 语句
- 如何在iOS上实现苹果电脑最小化窗口时的“神奇效果”(即吸入吸出效果在iPhone上的实现)
- Java Tutorial JDBC
- PHP (递归分类信息)
- 新买的阿里云服务器无法进行远程桌面
- DataTable 转换成 Json
- my97时间选择
- Myeclipse如何部署项目
- codeforces/contest/798/problem/B
- Linux 相关技能