Gossip less, immediately into the subject ...
The switch between the keyboard and the system's default keyboard is used in the development with the Pickerview customization. Hope to help the friends to use ...
#import "ViewController.h"
@interface Viewcontroller () <uitextviewdelegate, Uitextfielddelegate, uipickerviewdelegate>
@property (Weak, nonatomic) Iboutlet Uitextfield *textfield;
@property (Weak, nonatomic) Iboutlet Uitextview *textview;
/** Custom Keyboard */
@property (nonatomic, strong) Uipickerview *pickerview;
/** cause array */
@property (nonatomic, strong) Nsarray *reasonarray;
@property (nonatomic, assign) BOOL IsFirst;
@end
@implementation Viewcontroller
-(Ibaction) Click: (ID) Sender {
[Self.textfield Resignfirstresponder];
}
-(void) Viewdidload {
[Super Viewdidload];
Self.textView.delegate = self;
Self.textField.delegate = self;
Self.textField.inputView = Self.pickerview;
}
-(void) Viewdidappear: (BOOL) Animated {
[Super viewdidappear:animated];
[Self.textfield Becomefirstresponder];
}
-(void) Viewdiddisappear: (BOOL) Animated {
[Super viewdiddisappear:animated];
[Self.textfield Resignfirstresponder];
}
/*****************************************/
#pragma mark-uitextviewdelegate
-(BOOL) textviewshouldbeginediting: (Uitextview *) TextView {
Toggle Keyboard
[Self.textfield Resignfirstresponder];
self.textField.enabled = NO;
Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (0.5 * nsec_per_sec)), Dispatch_get_main_queue (), ^{
[TextView Becomefirstresponder];
});
return YES;
}
-(void) textviewdidbeginediting: (Uitextview *) TextView {
self.textField.enabled = YES;
}
#pragma mark-uitextfielddelegate
-(BOOL) textfieldshouldbeginediting: (Uitextfield *) TextField {
Toggle Keyboard
[Self.textview Resignfirstresponder];
self.textView.editable = NO;
Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (0.5 * nsec_per_sec)), Dispatch_get_main_queue (), ^{
[TextField Becomefirstresponder];
});
if (_isfirst) {
[Self PickerView:self.pickerView didselectrow:0 incomponent:1];
_isfirst = NO;
}
return YES;
}
-(void) textfielddidbeginediting: (Uitextfield *) TextField {
self.textView.editable = YES;
}
Do not allow user input
-(BOOL) Texttitlefield: (Uitextfield *) Texttitlefield Shouldchangecharactersinrange: (nsrange) Range Replacementstring: (NSString *) string {
return NO;
}
/******************* Switch Keyboard **********************/
#pragma mark-uipickerviewreasonarraysource
-(Nsinteger) Numberofcomponentsinpickerview: (Uipickerview *) Pickerview {
return 1;
}
Number of rows
-(Nsinteger) Pickerview: (Uipickerview *) Pickerview numberofrowsincomponent: (Nsinteger) Component {
return self.reasonArray.count;
}
#pragma mark-uipickerveiwdelegate
-(NSString *) Pickerview: (Uipickerview *) Pickerview Titleforrow: (nsinteger) Row forcomponent: (Nsinteger) Component {
return Self.reasonarray[row];
}
Select a row
-(void) Pickerview: (Uipickerview *) Pickerview Didselectrow: (nsinteger) Row incomponent: (Nsinteger) Component {
Self.textField.text = Self.reasonarray[row];
}
#pragma mark-Lazy loading
-(Uipickerview *) Pickerview {
if (!_pickerview) {
_pickerview = [[Uipickerview alloc] init];
_pickerview.backgroundcolor = [Uicolor Lightgraycolor];
_pickerview.backgroundcolor = [Uicolor Whitecolor];
_pickerview.delegate = self;
}
return _pickerview;
}
-(Nsarray *) Reasonarray {
if (!_reasonarray) {
_reasonarray = @[@ "121313311", @ "121313311", @ "121313311", @ "121313311", @ "121313311", @ "121313311", @ "121313311", @ " 121313311 "@" 121313311 "@" 121313311 "@" 121313311 "@" 121313311 "];
}
return _reasonarray;
}
About iOS different types of keyboard switching