1: Change the style of the navigation bar uniformly, in APPDELEGATE.M
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions{Self.window=[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]; //Override point for customization after application launch.Self.window.backgroundColor =[Uicolor Whitecolor]; //set the navigation bar style[self customizeinterface]; if([Login IsLogin]) {[Self setuptabviewcontroller]; }Else{[UIApplication sharedapplication].applicationiconbadgenumber=0; [Self setuploginviewcontroller]; } [Self.window makekeyandvisible]; returnYES;}- (void) Customizeinterface {//set the background and title colors of NavUinavigationbar *navigationbarappearance =[Uinavigationbar appearance]; Nsdictionary*textattributes =Nil; if(Nsfoundationversionnumber >Nsfoundationversionnumber_ios_6_1) {[Navigationbarappearance settintcolor:[uicolor Whitecolor]];//returns the arrow color of the button[[Uitextfield appearance] Settintcolor:[uicolor colorwithhexstring:@"0x3bbc79"]];//set the cursor color of Uitextfield[[Uitextview appearance] Settintcolor:[uicolor colorwithhexstring:@"0x3bbc79"]];//set the cursor color of Uitextview[[Uisearchbar appearance] Setbackgroundimage:[uiimage imagewithcolor:[uicolor colorwithhexstring:@"0xe5e5e5"]] Forbarposition:0Barmetrics:uibarmetricsdefault]; Textattributes=@{nsfontattributename: [Uifont boldsystemfontofsize:knavtitlefontsize], Nsforegroundcolorattributename: [Uicolor whitecolor],}; } Else {#if__iphone_os_version_min_required < __iphone_7_0[[Uisearchbar appearance] Setbackgroundimage:[uiimage imagewithcolor:[uicolor colorwithhexstring:@"0xe5e5e5"]]]; Textattributes=@{uitextattributefont: [Uifont boldsystemfontofsize:knavtitlefontsize], Uitextattributetextcolor: [Uicolor Whitecolor], uitextattributetextshadowcolor: [Uicolor Clearcolor], Uitextattributetextshadowoffset: [Nsvalue Valuewithuioffset:uioffsetzero], };#endif} [navigationbarappearance setbackgroundimage:[uiimage imagewithcolor:[uicolor colorwithhexstring:@"0x28303b"] ] [forbarmetrics:uibarmetricsdefault]; [Navigationbarappearance settitletextattributes:textattributes];} One of the above versions determines: Foundation_exportDoubleNsfoundationversionnumber;#ifTarget_os_iphone#defineNsfoundationversionnumber_iphoneos_2_0 678.24#defineNsfoundationversionnumber_iphoneos_2_1 678.26#defineNsfoundationversionnumber_iphoneos_2_2 678.29#defineNsfoundationversionnumber_iphoneos_3_0 678.47#defineNsfoundationversionnumber_iphoneos_3_1 678.51#defineNsfoundationversionnumber_iphoneos_3_2 678.60#defineNsfoundationversionnumber_ios_4_0 751.32#defineNsfoundationversionnumber_ios_4_1 751.37#defineNsfoundationversionnumber_ios_4_2 751.49#defineNsfoundationversionnumber_ios_4_3 751.49#defineNsfoundationversionnumber_ios_5_0 881.00#defineNsfoundationversionnumber_ios_5_1 890.10#defineNsfoundationversionnumber_ios_6_0 992.00#defineNsfoundationversionnumber_ios_6_1 993.00#defineNsfoundationversionnumber_ios_7_0 1047.20#defineNsfoundationversionnumber_ios_7_1 1047.25#endif
2: Determine if a view has been loaded with nil = = View.superview
if (nil = = View.superview) { // to determine if a view has been loaded , if it is loaded, its superview will not be nil cgrect frame = scrollview0.frame; = frame.size.width * page; 0 ; = frame; [ScrollView0 Addsubview:view]; }
3: Baidu map Initialization coordinate range
- (void) viewdidload {[Super viewdidload]; [UIApplication Sharedapplication].applicationiconbadgenumber= the; _mapview=[[bmkmapview Alloc] Initwithframe:cgrectmake (0,0, the, -)]; Bmkcoordinateregion region; ////representing the scope of the structure bodyRegion.center.latitude =24.27;//in the centerRegion.center.longitude =118.06; Region.span.latitudeDelta=0.1;//Longitude Range (set to 0.1 to indicate a latitude range of 0.2)Region.span.longitudeDelta =0.1;//Latitude Range[_mapview setregion:region]; [Self.baiduview Addsubview:_mapview];} Picture of a custom pin:-(Bmkannotationview *) Mapview: (Bmkmapview *) Mapview viewforannotation: (ID <BMKAnnotation>) annotation{if([Annotation iskindofclass:[bmkpointannotationclass]]) {Bmkpinannotationview*newannotationview = [[Bmkpinannotationview alloc] initwithannotation:annotation reuseidentifier:@"myannotation"]; Newannotationview.pincolor=bmkpinannotationcolorpurple; Newannotationview.animatesdrop= YES;//set the callout point animation displayNewannotationview.image = [UIImage imagenamed:@"iphone"];//change a pin to another picture returnNewannotationview; } returnNil;}
4: Hide Keyboard
when there are multiple Uitextfield on the current view, hide the keyboard, traversing all of the view's child views to set it to a non-first response if it is Uitextfield of course, If you want to hide the Uitextfield on the child view, you can further determine the number of view subviews, if more than 1 traverse the view's child view, and then do similar//Hide Keyboard There are multiple Uitextfield on the current view for(UIView *viewinch[Self.view Subviews]) { if(View isKindofclass:[uitextfield Class]) {[View Resignfirstrespond]; }} directly cancels the various view keyboards on the current window with [Self.view endediting:no] [[[[UIApplication sharedapplication] Keywindow] Endediting:yes ], or use the following code-(BOOL) textfieldshouldbeginediting: (Uitextfield *) Textfield{uitapgesturerecognizer*tapgesturerecognizer =[[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (done:)]; Tapgesturerecognizer.numberoftapsrequired=1; [Self.view Addgesturerecognizer:tapgesturerecognizer]; //just click on the non-text input area to respond to HidekeyboardreturnYES;}
Coordinate transformations in the 5:uiview
//converts pixel point from view to target view, returns the pixel value in the target view-(Cgpoint) Convertpoint: (cgpoint) point toview: (UIView *) view;//converts a pixel point from view to the current view, returning the pixel value in the current view-(Cgpoint) Convertpoint: (cgpoint) point fromview: (UIView *) view;//converts a rect from the view of a rect to the target view, returning the RECT in the target view-(CGRect) Convertrect: (cgrect) rect toview: (UIView *) view;//converts a rect from view to the current view, returning a rect in the current view-(CGRect) Convertrect: (cgrect) rect fromview: (UIView *view; convert Subview (BTN) frame in UITableViewCell to Controllera//there is a uitableview in the Controllera, there is a button on Uitableviecell,cell in UITableView .//implemented in Controllera:CGRect rc =[cell ConvertRect:cell.btn.frame ToView:self.view]; or CGRect RC=[Self.view convertRect:cell.btn.frame Fromview:cell];//This RC is a rect of btn in Controlleraor when known btn: CGRect RC=[Btn.superview convertRect:btn.frame ToView:self.view]; or CGRect RC=[Self.view ConvertRect:btn.frame FromView:btn.superview]; For example: Cgpoint Origin=[self Convertpoint:cgpointzero toview:[uiapplication Sharedapplication].keywindow]; Convert Self's 0-point coordinate system to Keywindow's coordinate system and get an "absolute" coordinate. A coordinate of 0 in the parent control.0In fact, the parent control would have coordinates 200, $This 200,200 value can be obtained through the above
6: Pop up a view and have a back view (gross code)
-(UIView *) mytapbackgroundview{if(!_mytapbackgroundview) {_mytapbackgroundview=({UIView*view =[[UIView alloc] initwithframe:kscreen_bounds]; View.backgroundcolor=[Uicolor Clearcolor]; UITapGestureRecognizer*tap =[[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (changeshowing)]; [View Addgesturerecognizer:tap]; View }); } return_mytapbackgroundview;}-(UIView *) mycontentview{if(!_mycontentview) {_mycontentview=({UIView*view =[[UIView alloc] Initwithframe:cgrectzero]; View.backgroundcolor=[Uicolor Whitecolor]; View }); } return_mycontentview;}- (void) changeshowing{[Kkeywindow Endediting:yes]; if(!_mycontentview) {//not loaded in[self loaduielement]; } Cgpoint Origin=[self Convertpoint:cgpointzero toview:kkeywindow]; CGFloat contentheight= self.isshowing?0: kcodebranchtagbutton_contentheight; if(self.isshowing) {//Hiddenself.enabled =NO; [UIView animatewithduration:0.3animations:^{Self.myTapBackgroundView.backgroundColor= [Uicolor colorwithwhite:0Alpha0]; Self.myContentView.alpha=0; Self.myContentView.frame= CGRectMake (0, origin.y-contentheight, Kscreen_width, contentheight); Self.imageView.transform= Cgaffinetransformrotate (Self.imageView.transform, Degrees_to_radians ( the)); } Completion:^(BOOL finished) {[Self.mytapbackgroundview Removefromsuperview]; [Self.mycontentview Removefromsuperview]; Self.enabled=YES; Self.isshowing=NO; }]; }Else{//ShowSelf.myContentView.frame = CGRectMake (0, ORIGIN.Y, Kscreen_width,0); [Kkeywindow AddSubview:self.myTapBackgroundView]; [Kkeywindow AddSubview:self.myContentView]; Self.enabled=NO; [UIView animatewithduration:0.3animations:^{Self.myTapBackgroundView.backgroundColor= [Uicolor colorwithwhite:0Alpha0.2]; Self.myContentView.alpha=1.0; Self.myContentView.frame= CGRectMake (0, origin.y-contentheight, Kscreen_width, contentheight); Self.imageView.transform= Cgaffinetransformrotate (Self.imageView.transform, Degrees_to_radians ( the)); } Completion:^(BOOL finished) {self.enabled=YES; Self.isshowing=YES; }]; }} Where:#definekscreen_bounds [UIScreen mainscreen].bounds#defineKkeywindow [UIApplication Sharedapplication].keywindow
iOS Client Coding Project record (v)