Unity调用IOS时间日期控件UIDatePicker
来源:互联网 发布:淘宝怎么凑单 编辑:程序博客网 时间:2024/05/17 05:54
没什么好解析的上代码:
//***************************************日历、时间UIDatePicker* datePicker;-(void)DP_ShowPicker{ if (datePicker!=nil) { [self DP_removeViews:nil]; } UIViewController *vc = UnityGetGLViewController(); CGRect toolbarTargetFrame = CGRectMake(0, vc.view.bounds.size.height-216-44, [self GetW], 44); CGRect datePickerTargetFrame = CGRectMake(0, vc.view.bounds.size.height-216, [self GetW], 216); CGRect darkViewTargetFrame = CGRectMake(0, vc.view.bounds.size.height-216-44, [self GetW], 260); UIView *darkView = [[UIView alloc] initWithFrame:CGRectMake(0, vc.view.bounds.size.height, [self GetW], 260)]; darkView.alpha = 1; darkView.backgroundColor = [UIColor whiteColor]; darkView.tag = 9; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(DP_dismissDatePicker:)]; [darkView addGestureRecognizer:tapGesture]; [vc.view addSubview:darkView]; datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, vc.view.bounds.size.height+44, [self GetW], 216)]; datePicker.tag = 10; [datePicker addTarget:self action:@selector(DP_changeDate:) forControlEvents:UIControlEventValueChanged]; datePicker.datePickerMode = UIDatePickerModeDateAndTime;//日历时间样式,可以是单独的时间或者日历 [vc.view addSubview:datePicker]; UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, vc.view.bounds.size.height, [self GetW], 44)]; toolBar.tag = 11; toolBar.barStyle = UIBarStyleDefault; UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(DP_dismissDatePicker:)]; [toolBar setItems:[NSArray arrayWithObjects:spacer, doneButton, nil]]; [vc.view addSubview:toolBar]; [UIView beginAnimations:@"MoveIn" context:nil]; toolBar.frame = toolbarTargetFrame; datePicker.frame = datePickerTargetFrame; darkView.frame = darkViewTargetFrame; [UIView commitAnimations];}-(CGFloat) GetW{ UIViewController *vc = UnityGetGLViewController(); bool IsLandscape; UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { IsLandscape = true; } else { IsLandscape = false; } CGFloat w; if(IsLandscape) { w = vc.view.frame.size.height; } else { w = vc.view.frame.size.width; } //NSLog(@"--- System Version: %@", [UIDevice currentDevice].systemVersion); NSArray *vComp = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."]; if ([[vComp objectAtIndex:0] intValue] >= 8) { w = vc.view.frame.size.width; } return w;}- (void)DP_changeDate:(UIDatePicker *)sender{ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat: @"yyyy-MM-dd hh:mm"]; NSString *dateString = [dateFormatter stringFromDate:sender.date]; NSLog(@"--- DateChangedEvent: %@", dateString); UnitySendMessage( [m_pstrObjectName UTF8String], [m_pstrFuncName UTF8String], dateString.UTF8String);}-(void) DP_PickerClosed:(UIDatePicker *)sender{ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat: @"yyyy-MM-dd hh:mm"]; NSString *dateString = [dateFormatter stringFromDate:sender.date]; NSLog(@"--- DateClosedEvent: %@", dateString); UnitySendMessage( [m_pstrObjectName UTF8String], [m_pstrFuncName UTF8String], dateString.UTF8String); }- (void)DP_dismissDatePicker:(id)sender{ NSLog(@"--- DismissDatPicker"); UIViewController *vc = UnityGetGLViewController(); [self DP_PickerClosed:datePicker]; CGRect toolbarTargetFrame = CGRectMake(0, vc.view.bounds.size.height, [self GetW], 44); CGRect datePickerTargetFrame = CGRectMake(0, vc.view.bounds.size.height+44, [self GetW], 216); CGRect darkViewTargetFrame = CGRectMake(0, vc.view.bounds.size.height, [self GetW], 260); [UIView beginAnimations:@"MoveOut" context:nil]; [vc.view viewWithTag:9].frame = darkViewTargetFrame; [vc.view viewWithTag:10].frame = datePickerTargetFrame; [vc.view viewWithTag:11].frame = toolbarTargetFrame; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(DP_removeViews:)]; [UIView commitAnimations];}- (void)DP_removeViews:(id)object{ NSLog(@"--- removeViews"); if(datePicker==nil) { return; } UIViewController *vc = UnityGetGLViewController(); [[vc.view viewWithTag:9] removeFromSuperview]; [[vc.view viewWithTag:10] removeFromSuperview]; [[vc.view viewWithTag:11] removeFromSuperview];}//*********************
UnitySendMessage( [m_pstrObjectName UTF8String], [m_pstrFuncName UTF8String], dateString.UTF8String);参数参考文章:Unity Android/IOS 打开图片库和相机,并加载图片
0 0
- Unity调用IOS时间日期控件UIDatePicker
- iOS开发-UI控件:UIDatePicker日期/时间选取器(滚轮)
- Unity for iOS 调用UIDatePicker
- iOS 时间/ 日期选择器 UIDatePicker
- iOS的UIDatePicker时间控件
- 【UIDatePicker日期选择器控件】
- UIDatePicker 日期/时间选取器(滚轮)—IOS开发
- UIDatePicker 日期/时间选取器(滚轮)—IOS开发
- UIDatePicker 日期/时间选取器(滚轮)—IOS开发
- UIDatePicker 日期/时间选取器(滚轮)—IOS开发
- UIDatePicker 日期/时间选取器(滚轮)—IOS开发
- UIDatePicker 日期/时间选取器(滚轮)—IOS开发
- UIDatePicker 日期/时间选取器(滚轮)—IOS开发
- UIDatePicker 日期/时间选取器(滚轮)—IOS开发
- UIDatePicker 日期/时间选取器(滚轮)—IOS开发
- UIDatePicker 日期/时间选取器(滚轮)—IOS开发
- UIDatePicker 日期/时间选取器(滚轮)—IOS开发
- iOS 控件之 UIDatePicker
- 在android 中开发java.net.SocketException: socket failed: EACCES (Permission denied) 报错
- 邮票分你一半
- mssql游标
- Android拍照、裁剪与相册处理
- Android--从零单排系列(1)--打电话,发短信
- Unity调用IOS时间日期控件UIDatePicker
- JVM性能调优5:Heap堆分析方法
- iOS-沙盒路径
- 1007. Maximum Subsequence Sum (25)
- 对象序列化
- java获取cpu、内存、硬盘信息
- Java 7之基础 - 强引用、弱引用、软引用、虚引用
- 算法复习:最大团问题(回溯法和分支限界法)
- Linux系统中采用Atlas+Keepalived实现MySQL读写分离、负载均衡