1. The navigation bar modifies the title and drives the Picture property
Effect
This needs to be catransition. Examples such as the following
// Facility navigation bar title, directly using Self.title is not animated -(void) setnav{ *lab = [[UILabel alloc]initwithframe: CGRectMake (00)]; @" Navigation bar " ; = [Uicolor blackcolor]; = Lab;}
//Toggle Title Animation-(void) clicknavrightbar{catransition*animation =[catransition animation]; Animation.duration=1.0; Animation.type=Kcatransitionpush; Animation.subtype=Kcatransitionfromtop; Animation.timingfunction=[Camediatimingfunction functionwithname:kcamediatimingfunctioneaseineaseout]; [Self.navigationItem.titleView.layer addanimation:animation Forkey:@"Changetitle"]; NSString*titlestr = ((uilabel*). Self.navigationItem.titleView). Text; if([Titlestr isequaltostring:@"Navigation bar"]) {(UILabel*) self.navigationItem.titleView). Text =@"Change the"; } Else{(UILabel*) self.navigationItem.titleView). Text =@"Navigation bar"; }}
Use of the group function in 2.GCD
If an interface consists of two parts, A and B, the data is returned by two interfaces. Now the requirement is that only the two interface data are loaded before the next step can be done.
Then you can use the GCD group function
dispatch_group_t group = Dispatch_group_create (); Dispatch_group_async (Group, Dispatch_get_global_queue (Dispatch_queue_priority_default, 0 ), ^{ // a partial data [self Dosomethinga];}); Dispatch_group_async (Group, Dispatch_get_global_queue (Dispatch_queue_priority_default, 0 ), ^{ // b partial data [self dosomethingb];}); Dispatch_group_notify (Group, Dispatch_get_main_queue (), ^{ // processing after the request is completed });
Where Dosomethinga and DOSOMETHINGB are both synchronous, this is no problem.
If a, B processes the data is block, and is asynchronous. Then there will be a problem with this writing. Because Async does not block the current thread, a, b data will start executing "after the request has been completed" before it has finished processing. So this should be the
dispatch_group_t Group =dispatch_group_create ();d ispatch_group_enter (group); [[Testblockmodel Sharedinstance]executewithstr:nil Block:^ (NSString *parameter) { //processing Part A data//... ....Dispatch_group_leave (group);}]; Dispatch_group_enter (group); [[Testblockmodel Sharedinstance]executewithstr:nil Block:^ (NSString *parameter) { //processing Part B data//... ....Dispatch_group_leave (group);}]; Dispatch_group_notify (Group, Dispatch_get_main_queue (),^{ //processing after the request is complete});
3. Modify the color of the Uisearchbar Clear button, you can use
UIImage *imgclear = [UIImage imagenamed:@ "nav_icon_close"];[ Searchbar setimage:imgclear forsearchbaricon:uisearchbariconclear State:uicontrolstatenormal]; [Searchbar setimage:imgclear forsearchbaricon:uisearchbariconclear state:uicontrolstatehighlighted];
4. Image click Method
When you have multiple controls on a view, you want to write a way to click on the image. Then you can use:
The previous wording was written by
uiimageview *imgview = [[Uiimageview alloc]initwithframe:cgrectmake (0 , 0 , Kheadiconheight, kheadiconheight)];imgview.image = [UIImage imagenamed:@ " head_icon " ]; imgview.userinteractionenabled = YES; UITapGestureRecognizer *tap = [[UITapGestureRecognizer Alloc]initwithtarget: Self action: @selector (Clickheadicon)]; [Imgview Addgesturerecognizer:tap]; -(void @ " Click the Avatar "
This is the most common notation. can now be resolved in another way, this method is mostly consistent with the above, but the difference is not to add imgview.userinteractionenabled = yes this method. Whether the clicked point is within the Imgview to determine whether the triggering event occurred.
-(BOOL) Pointinside: (cgpoint) point withevent: (Uievent *)Event { //judging the clicked Point, not in the circleCgpoint Center =Self.imgView.center; CGFloat R= Self.imgView.frame.size.width *0.5; CGFloat NEWR= sqrt ((center.x-point.x) * (center.x-point.x) + (CENTER.Y-POINT.Y) * (CENTER.Y-point.y)); if(Newr >r) {return false; } Else { return true; }}
5.label Adaptive Fonts
Label font, height OK, let width fit. Now there is a need to be width, height must be, let the font adaptive. can be used
Label.adjustsfontsizetofitwidth = YES;
This line of code is enough.
6. Determine whether a string is a decimal point or a numeric component
#define NUMBERS @ "0123456789." /* */-(BOOL) isonlyhasnumberandpointwithstring: (NSString *)string{ *cs= [[Nscharacterset charactersetwithcharactersinstring:numbers] invertedset]; *filter=[[string Componentsseparatedbycharactersinset:cs] componentsjoinedbystring:@ "" ]; return [string isequaltostring:filter];}
7. When TableView reloadsections, strange animations can occur even when animating to Uitableviewrowanimationnone. such as staggered etc.
[Self.tableview reloadsections:set withrowanimation:uitableviewrowanimationnone];
There are two solutions at this time
① replace reloadsections with Reloaddata, refresh the local to refresh the whole, but this violates the original intention
② force the animation to cancel
[UIView performwithoutanimation:^{ [self.tableview reloadsections:set withrowanimation : Uitableviewrowanimationnone];}];
iOS work notes (17)