Date input in ios calendar View

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.