IOS client Coding project record (5), ios client coding project

Source: Internet
Author: User

IOS client Coding project record (5), ios client coding project

1: Modify the style of the navigation bar in a unified manner, in AppDelegate. m

-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( 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 mimizeinterface]; if ([Login isLogin]) {[self setupTabViewController];} else {[UIApplication sharedApplication]. applicationIconBadgeNumber = 0; [self setupLoginViewController];} [self. window makeKeyAndVisible]; return YES;}-(void) mimizeinterface {// set the background color and title Color of the Nav; optional * navigationBarAppearance = [UINavigationBar appearance]; NSDictionary * textAttributes = nil; if (NSFoundationVersionNumber> Custom) {[navigationBarAppearance setTintColor: [UIColor whiteColor]; // The Arrow color of the return button [[UITextField appearance] setTintColor: [UIColor colorWithHexString: @ "0x3bbc79"]; // set the UITextField cursor color [[UITextView appearance] setTintColor: [UIColor colorWithHexString: @ "0x3bbc79"]; // set the UITextView cursor color [[UISearchBar appearance] colors: [UIImage imageWithColor: [UIColor colorWithHexString: @ "photo"] forBarPosition: 0 barMetrics: UIBarMetricsDefault]; textAttributes =@{ NSFontAttributeName: [UIFont boldSystemFontOfSize: kNavTitleFontSize], NSForegroundColorAttributeName: [UIColor whiteColor],};} else {# if _ items <_ IPHONE_7_0 [[UISearchBar appearance] setBackgroundImage: [UIImage imageWithColor: [UIColor colorWithHexString: @ "image"]; textAttributes =@{ attributes: [UIFont boldSystemFontOfSize: blank], direction: [UIColor whiteColor], direction: [UIColor clearColor], direction: [NSValue valueWithUIOffset: UIOffsetZero], };#endif} [navigationBarAppearance progress: [UIImage imageWithColor: [UIColor colorWithHexString: @ "0x28303b"] forBarMetrics: seconds]; [navigationBarAppearance attributes: textAttributes];} the previous version determines FOUNDATION_EXPORT double second; # if TARGET_ OS _IPHONE # define limit 678.24 # define limit 678.26 # define NSFoundationVersionNumber_iPhoneOS_2_2 678.29 # define limit 678.47 # define limit 678.51 # define limit 678.60 # define limit 751.32 # define limit 751.37 # define limit 751.49 # define limit 751.49 # define limit 881.00 # define NSFoundationVersionNumber_iOS_5_1 890.10 # define limit 992.00 # define NSFoundationVersionNumber_iOS_6_1 993.00 # define limit 1047.20 # define limit 1047.25 # endif

 

2: Determine whether a view has been loaded with nil = view. superview

If (nil = view. superview) {// determine whether a view has been loaded. If it has been loaded, its superview will not be nil CGRect frame = scrollView0.frame; frame. origin. x = frame. size. width * page; frame. origin. y = 0; view. frame = frame; [scrollView0 addSubview: view];}

 

3: Coordinates of Baidu map Initialization

-(Void) viewDidLoad {[super viewDidLoad]; [UIApplication sharedApplication]. applicationIconBadgeNumber = 15; _ mapView = [[BMKMapView alloc] initWithFrame: CGRectMake (0, 0,320,400)]; BMKCoordinateRegion region; // indicates the region of the struct in the range. center. latitude = 24.27; // region in the center. center. longpolling = 118.06; region. span. latitudeDelta = 0.1; // the longitude range (set to 0.1 to indicate the latitude range of the display range to 0.2) region. span. longitudeDelta = 0.1; // latitude range [_ mapView setRegion: region]; [self. baiduView addSubview: _ mapView];} custom pin image:-(optional *) mapView :( BMKMapView *) mapView viewForAnnotation :( id <BMKAnnotation>) annotation {if ([annotation isKindOfClass: [BMKPointAnnotation class]) {BMKPinAnnotationView * newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @ "myAnnotation"]; newAnnotationView. pinColor = BMKPinAnnotationColorPurple; newAnnotationView. animatesDrop = YES; // set newAnnotationView for the annotation animation. image = [UIImage imageNamed: @ "iphone"]; // change the pin to another image. return newAnnotationView;} return nil ;}

 

4: Hide the keyboard

When there are multiple uitextfields in the current view, to hide the keyboard, first traverse all the subviews of the view. If it is uitextfield, set it to not the first response. Of course, if you want to hide the UITextField on the subview, You can further judge the number of subviews of the view. If the value is greater than 1, you can traverse the subview of the view, then perform a similar operation // hide multiple uitextfieldfor (UIView * view in [self. view subviews]) {if (view is kindofclass: [UITextField Class]) {[view resignfirstrespond] ;}} use [self. view endEditing: NO] directly cancel the keyboard of various views on the current Window [[[UIApplication sharedApplication] keyWindow] endEditing: YES]; or use the following code-(BOOL) textFieldShouldBeginEditing :( UITextField *) textField {parameter * tapGestureRecognizer = [[delealloc] initWithTarget: self action: @ selector (done :)]; tapGestureRecognizer. numberOfTapsRequired = 1; [self. view addGestureRecognizer: tapGestureRecognizer]; // The hideKeyBoardreturn is returned only when you click the non-text input area ;}

 

5. Coordinate Transformation in UIView

// Convert the pixel point from the view where the point is located to the target view, and return the pixel value-(CGPoint) convertPoint :( CGPoint) point toView (UIView *) view in the target view; // switch the pixel point from the view to the current view, and return the pixel value-(CGPoint) convertPoint :( CGPoint) point fromView (UIView *) view in the current view; // convert the rect view from the rect view to the target view, and return the rect-(CGRect) convertRect :( CGRect) rect toView :( UIView *) view in the target view; // switch the rect from the view to the current view, and return the rect-(CGRect) convertRect :( CGRect) rect fromView :( UIView *) view in the current view; for example, convert the frame of subview (btn) in UITableViewCell to controllerA. // There Is A UITableView in controllerA. There are multiple UITableVieCell lines in UITableView, and a button in the cell is 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 controllerA or CGRect rc = [btn when btn is known. 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]; place the zero-point coordinate system of self in the coordinate system of keyWindow for conversion, obtain an "absolute" coordinate. The coordinate in the parent control is 0, 0. In fact, the parent control has a coordinate of 200,200. You can obtain this 200,200 value through the above.

 

6: A view is displayed, and a view with a back (General Code) is displayed)

-(UIView *) myTapBackgroundView {if (! _ MyTapBackgroundView) {_ myTapBackgroundView = ({UIView * view = [[UIView alloc] initWithFrame: kScreen_Bounds]; view. backgroundColor = [UIColor clearColor]; optional * 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) {// [self loadUIElement] has not been loaded;} CGPoint origin = [self convertPoint: CGPointZero toView: kKeyWindow]; CGFloat contentHeight = self. isShowing? 0: kCodeBranchTagButton_ContentHeight; if (self. isShowing) {// hide self. enabled = NO; [UIView animateWithDuration: 0.3 animations: ^ {self. myTapBackgroundView. backgroundColor = [UIColor colorWithWhite: 0 alpha: 0]; 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 (180);} completion: ^ (BOOL finished) {[self. myTapBackgroundView removeFromSuperview]; [self. myContentView removeFromSuperview]; self. enabled = YES; self. isShowing = NO;}];} else {// display self. myContentView. frame = CGRectMake (0, origin. y, kScreen_Width, 0); [kKeyWindow addSubview: self. myTapBackgroundView]; [kKeyWindow addSubview: self. myContentView]; self. enabled = NO; [UIView animateWithDuration: 0.3 animations: ^ {self. myTapBackgroundView. backgroundColor = [UIColor colorWithWhite: 0 alpha: 0.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 (180);} completion: ^ (BOOL finished) {self. enabled = YES; self. isShowing = YES;}] ;}} where: # define kScreen_Bounds [UIScreen mainScreen]. bounds # define kKeyWindow [UIApplication sharedApplication]. keyWindow

 

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.