Daily Update attention :http://weibo.com/hanjunqiang Sina Weibo!
Click Return to cancel TextView's responder
-(BOOL) Textfieldshouldreturn: (Uitextfield *) textfield{ [_contacttextfiled Resignfirstresponder]; return YES;} -(BOOL) TextView: (Uitextview *) TextView Shouldchangetextinrange: (nsrange) Range Replacementtext: (NSString *) text{ if ([text isequaltostring:@ "\ n"]) { [TextView resignfirstresponder]; [_contacttextfiled Becomefirstresponder]; return YES; } return YES;}
iOS One line of code removes all child views from the parent view
The main use of a makeObjectsPerformSelector: function here. This function can be used in many scenarios to simplify the code.
[Xxxview.subviews makeobjectsperformselector: @selector (Removefromsuperview)];
resolves an issue that refreshes a single cell or section flash:
[UIView Setanimationsenabled:no]; [_listtable beginupdates]; [_listtable reloadsections:[nsindexset indexSetWithIndex:indexPath.section] Withrowanimation: Uitableviewrowanimationnone]; [_listtable endupdates]; [UIView Setanimationsenabled:yes];
Daily Update attention :http://weibo.com/hanjunqiang Sina Weibo!
Draw the following curves:
UIView *mycustomview = [[UIView alloc]initwithframe:cgrectmake (0, 204,kscreenwidth, +)]; Mycustomview.backgroundcolor = [Uicolor whitecolor]; [View Addsubview:mycustomview]; Uibezierpath *bezierpath = [Uibezierpath Bezierpath]; [Bezierpath Movetopoint:cgpointmake (0,0)]; [Bezierpath addcurvetopoint:cgpointmake (mycustomview.width, 0) controlpoint1:cgpointmake (0, 0) ControlPoint2: Cgpointmake (MYCUSTOMVIEW.WIDTH/2, +)]; [Bezierpath Addlinetopoint:cgpointmake (Mycustomview.width, Mycustomview.height)]; [Bezierpath addlinetopoint:cgpointmake (0, Mycustomview.height)]; [Bezierpath Closepath]; Cashapelayer *shaplayer = [Cashapelayer layer]; Shaplayer.path = Bezierpath.cgpath; MyCustomView.layer.mask = Shaplayer; MyCustomView.layer.masksToBounds = YES;
When you use Uisearchcontroller to implement the search bar in UITableView, when the search box has been activated and pushed into the new VC, there will be a search box overlap: That is Definespresentationcontext this boolean value!
Daily Update Attention :http://weibo.com/hanjunqiang Sina Weibo!
the hidden and disappearing of TabBar:
-(void) Hidestabbar: (BOOL) hidden{[UIView Beginanimations:nil context:null]; [UIView setanimationduration:0]; For (UIView *view in self.tabBarController.view.subviews) {if ([View Iskindofclass:[uitabbar class]]) { if (hidden) {[View Setframe:cgrectmake (view.frame.origin.x, [UIScreen Mainscreen].bounds.size.heigh T, View.frame.size.width, View.frame.size.height)]; }else{[View Setframe:cgrectmake (view.frame.origin.x, [UIScreen mainscreen].bounds.size.height-49, VIEW.F Rame.size.width, View.frame.size.height)]; }}else{if ([View iskindofclass:nsclassfromstring (@ "Uitransitionview")]) {if (hidden) { [View Setframe:cgrectmake (view.frame.origin.x, VIEW.FRAME.ORIGIN.Y, View.frame.size.width, [UIScreen Main Screen].bounds.size.height)]; }else{[View Setframe:cgrectmake (View.frame.origin.x, view.frame.orIGIN.Y, View.frame.size.width, [UIScreen mainscreen].bounds.size.height-49)]; }}}} [UIView commitanimations];}
Gets the partition and number of rows on the cell where the button is located:
UIView *view = [Sender Superview]; Get view Gccollectgroupcelltableviewcell *cell = (gccollectgroupcelltableviewcell*) [view Superview] for parent views; Get cell Nsindexpath *indexpath = [_listtable Indexpathforcell:cell];//Get cell corresponding partition NSLog (@ "%@", detailarr[ indexpath.section-1][indexpath.row][@ "Comname"]);
Nsattributedstring and NSString Transfer:
nsattributedstring * Attrstr = [[Nsattributedstring alloc] initwithdata:[_companyfileds.comname dataUsingEncoding: Nsunicodestringencoding] options:@{Nsdocumenttypedocumentattribute:nshtmltextdocumenttype} documentAttributes: Nil Error:nil]; _companyfileds.comname = attrstr.string;
Monitor Uitextfield changes:
Register for monitoring [[Nsnotificationcenter defaultcenter]postnotificationname:uitextfieldtextdidchangenotification Object:nil] ; [[Nsnotificationcenter defaultcenter]addobserver:self selector: @selector (changeforkeyword:) Name: Uitextfieldtextdidchangenotification object:nil];//Monitor _pagetextfield.text Change-(void) Changeforkeyword: ( Nsnotification *) sender{[self checknum:_pagetextfield.text];} -(BOOL) Checknum: (NSString *) str{nsstring *regex = @ "^[0-9]+ (. [ 0-9]{2})? $ "; Nspredicate *pred = [Nspredicate predicatewithformat:@ "Self MATCHES%@", regex]; BOOL IsMatch = [pred evaluatewithobject:str]; if (!ismatch && _pagetextfield.text.length>0) {Uialertview *alertview = [[Uialertview alloc]initwithtit Le:nil message:@ "page number can only enter the number Oh" delegate:self cancelbuttontitle:@ "re-enter" Otherbuttontitles:nil, nil]; Alertview.delegate = self; [Alertview show]; return NO; } return YES;
Listen for Uitextfield click events
[[Nsnotificationcenter defaultcenter]postnotificationname:uitextfieldtextdidbegineditingnotification Object:nil] ; [[Nsnotificationcenter defaultcenter]addobserver:self selector: @selector (enteredited:) Name: Uitextfieldtextdidbegineditingnotification Object:nil]; -(void) enteredited: (Nsnotification *) Sender {
Daily Update attention :http://weibo.com/hanjunqiang Sina Weibo!
Resolution added to Parent view gestures that affect child view gestures: (gesture conflict)
Method One: #pragma mark--uigesturerecognizerdelegate-(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldreceivetouch: (Uitouch *) touch{ if ([Touch.view Iskindofclass:[uibutton class]]| | [Touch.view Iskindofclass:[uitableviewcell class]]| | [Touch.view Iskindofclass:[uitextfield class]]| | [Touch.view Iskindofclass:[uitextview class]]) { return NO; } return YES;}
Method Two://uiview the Exclusivetouch property//By setting [self setexclusivetouch:yes], can achieve the same interface multiple controls accept the event when the exclusivity, so as to avoid some problems.
Uitextfield border Style and content adjustment:
1. Set the time in the IB remember to choose a borderless, or you can set up, are not valid, is also a pit dead. _textboxname.layer.borderwidth=1.0f; _textboxname.layer.bordercolor=[uicolorcolorwithred:0xbf/255.0fgreen:0xbf/255.0fblue:0xbf/255.0falpha:1]. Cgcolor; 2. The distance from the left border of the Uitextfield Chinese character _textboxname.leftview=[[uiviewalloc] Initwithframe:cgrectmake (0,0, 16,51)]; _textboxname.leftviewmode=uitextfieldviewmodealways;
Picture Rotation Control:
#pragma mark-----Update button Animation-(void) Rotate360degreewithimageviews: (Uiimageview *) myviews{ cabasicanimation * Rotationanimation = [cabasicanimation animationwithkeypath:@ "Transform.rotation.z"]; Rotationanimation.tovalue = [NSNumber numberwithfloat:m_pi * 2.0]; Rotationanimation.duration = 1.0; rotationanimation.cumulative = yes;rotate360degreewithimageviews rotationanimation.repeatcount = 100000; [Myviews.layer addanimation:rotationanimation forkey:@ "Rotationanimation"];} [Myviews.layer removeallanimations]; Stop it
Change the cell's selected color:
Cell.selectedbackgroundview = [[UIView alloc] initWithFrame:cell.frame]; Cell.selectedBackgroundView.backgroundColor = Color_backgroundview; do not need any color to set this: Cell.selectionstyle = Uitableviewcellselectionstylenone;
Rounding Problem:
Objective-c expands C, and naturally many usages are consistent with C. For example, the floating-point number is converted into integers, there are four cases. 1. Simple rough, direct conversion of float F = 1.5; int A; A = (int) F; NSLog ("A =%d", a); the output is 1. (int) is a forced type conversion that discards the decimal part of a floating-point number. 2. Gaussian function, rounding down float f = 1.6; int A; A = Floor (f); NSLog ("A =%d", a); the output is 1. The floor () method is rounded down, similar to the Gaussian function in mathematics []. Gets the largest integer that is not greater than the floating-point number, for a positive number is the part of the floating-point number, for the complex number, discard the floating-point part after the minus 1.3.ceil function, rounding up. float F = 1.5; int A; A = Ceil (f); NSLog ("A =%d", a); the output is 2. The Ceil () method is rounded up to get the smallest integer not less than the floating-point number, and for positive numbers it discards the floating-point number and adds 1, which is the part of the floating-point number that is discarded for the plural. 4. Rounding by forcing type conversions. float F = 1.5; int A; A = (int) (f+0.5); NSLog ("A =%d", a);
iOS Developer Chat QQ Group: 446310206 Welcome to Join!
Daily Update attention :http://weibo.com/hanjunqiang Sina Weibo!
iOS project development error-prone Knowledge Point summary Han Junqiang's Blog