On the View Controller, when you touch textfield, you do not open a virtual keyboard, datepicker, or actionsheet. You need a calendar input box similar to html.
There are many open-source controls, but they are not what I want. Refer to kal to implement a calendar view of this type of function.
The calendar view is implemented in a custom view, and then added to the view of the view Controller. Finally, the calendar view is delegate to remove itself.
In the textFiled-(BOOL) textFieldShouldBeginEditing :( UITextField *) textField method, add an operation to open the calendar input view.
-(BOOL) textFieldShouldBeginEditing :( UITextField *) textField
{
GTMLoggerDebug (@ "textField tag is % d", textField. tag );
// [Self initialize mseguewithidentifier: @ "calendarViewCtl" sender: self];
[Self testCalView];
Return NO;
}
The date data required by the calendar view is obtained in one way, mainly from the NSCalendar that comes with the system.
-(Void) testCalView
{
Self. logicDao = [[XYCalendarDao alloc] initForDate: [NSDate date];
CalView = [[XYCalView alloc] initWithFrame: self. view. frame logicDao: self. logicDao];
CalView. delegate = self;
CATransition * transition = [CATransition animation];
Transition. type = kCATransitionPush;
Transition. subtype = kCATransitionFromTop;
Transition. duration = 0.6f;
Transition. fillMode = kCAFillModeForwards;
Transition. removedOnCompletion = YES;
Transition. timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut];
[CalView. layer addAnimation: transition forKey: @ "transition"];
NSLog (@ "calView is % @", NSStringFromCGRect (calView. frame ));
[Self. view addSubview: calView];
}
In the calendar View class, call its delegate method to close itself.
This is the delegate method of XYCalView.
-(Void) slideOutCalView :( XYCalDate *) selectedDate
{
[UIView animateWithDuration: 1 delay: 0 options: UIViewAnimationOptionCurveLinear animations: ^ {
CalView. frame = CGRectMake (0, calView. frame. size. height, calView. frame. size. width, calView. frame. size. height );
} Completion: ^ (BOOL finished ){
[CalView removeFromSuperview];
}];
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
[DateFormatter setDateFormat: @ "yyyy-MM-dd"];
NSString * strDate = [dateFormatter stringFromDate: [selectedDate NSDate];
Self. testCalendar. text = strDate;
}
Here, I use two ways to achieve the animation effect of the view, namely CATransition and UIView animation.