Basic knowledge of IOS development-fragment 19, basic knowledge of ios-Fragment

Source: Internet
Author: User

Basic knowledge of IOS development-fragment 19, basic knowledge of ios-Fragment

 

1: keyboard Event Sequence

UIKeyboardWillShowNotification // UIKeyboardDidShowNotification before the keyboard is displayed // UIKeyboardWillHideNotification after the keyboard is displayed // the keyboard is hidden before the keyboard is displayed // The keyboard size changes before the keyboard size changes

 

2: Program Report-[_ NSCFDictionary xxx]: unrecognized selector sen

The reason is that the object is a dictionary, so the dot syntax cannot be used. The solution to the postList. slots error is [postList valueForKey: @ "slots"]. You can use this syntax valueForKey.


3: UIScreen learning records

The UIScreen object contains the boundary rectangle of the entire screen. When constructing the user interface of an application, you should use the properties of this object to obtain the recommended rectangular size to construct your program window. CGRect bound = [[UIScreen mainScreen] bounds]; // The returned Rect CGRect frame with the status bar = [[UIScreen mainScreen] applicationFrame]; // The returned result is a Rect float scale without the status bar = [[UIScreen mainScreen] scale]; // to obtain the device's natural resolution, the scale attribute needs to be further described: in the past, the screen resolution of iphone devices was 320*480. apple later adopted the display technology named Retina in iPhone 4, and iPhone 4 adopted a display screen with a 960x640 pixel resolution. As the screen size remains unchanged, the resolution is increased by 3.5 inch to four times that of the iPhone 3GS, with an area of 326 pixels per inch. The scale attribute has two values: scale = 1, which indicates that the current device has a resolution of 320*480 (that is, the device before iPhone 4). scale = 2; when the resolution is 640*960 // determine the screen type, general or retina float scale = [UIScreen mainScreen]; if (scale = 1) {bIsRetina = NO; NSLog (@ "normal screen");} else if (scale = 2) {bIsRetina = YES; NSLog (@ "Retina screen ");} else {NSLog (@ "unknow screen mode! ");}

 

4: How to Use NSBundle objects in IOS development

Bundle is a directory that contains the resources used by the program. these resources contain images, sounds, compiled code, and nib files (bundle is also called plug-in ). corresponding bundle. cocoa provides the NSBundle class. our program is a bundle. in the Finder, an application looks no different from other files. but it is actually a directory that contains nib files, compiled code, and other resources. some resources in the main bundlebundle of the program can be localized. for example, for foo. nib, we can have two versions: one for English users and one for French users. the bundle contains two subdirectories: English. lproj and French. lproj. place the nib file in it. when the program needs to load foo. when a nib file is created, the bundle is automatically loaded based on the language specified. use the following method to obtain the main bundleNS of the program. Bundle * myBundle = [NSBundle mainBundle]; this method is generally used to obtain the bundle. if you need resources from other directories, you can specify a path to obtain bundleNSBundle * goodBundle; goodBundle = [NSBundle bundleWithPath :@"~ /. MyApp/Good. bundle "]; once we have an NSBundle object, we can access the resources in it. // Extension is optionalNSString * path = [goodBundle pathForImageResource: @" Mom "]; NSImage * momPhoto = [[NSImage alloc] initWithContentsOfFile: path]; bundle can contain a library. if we get a class from the library, bundle will connect to the library and find the Class: class newClass = [goodBundle classNamed: @ "Rover"]; id newInstance = [[newClass alloc] init]; if you do not know the class name, you can also find the main Class to obtain class aClass = [goodBundle principalClass]; id anInstance = [[aClass alloc] init]; you can see that NSBundle has many functions. in this chapter, NSBundle is responsible for loading nib files (in the background. we can also directly use NSBundle: BOOL successful = [NSBundle loadNibNamed: @ "About" owner: someObject] instead of using NSWindowController to load the nib file, we specified an object someObject as the File "s Owner of nib to obtain the XML File NSString * filePath = [[NSBundle mainBundle] pathForResouse: @" re "ofType: @" xml "]; NSData * data = [[NSData alloc] initWithContentsOfFile: filePath]; get the attribute list NSDictionary * dict = [NSDictionary attributes: [[NSBundle mainBundle] pathForResource: @ "ViewControllers" ofType: @ "plist"];

 

5: unit conversion, PX conversion to lbs

Using ps to design ios App fonts in pixels, while ios developers write code in lbs, the conversion between pixels and lbs. Is 30 PX converted into lbs. unit = 22 lbs = 2 lbs = (pixels/96) * 72 = (30/96) * 72 = 22.5 lbs Chinese font size VS English font size (lbs) VS pixel values: 8 = 5 lbs (5pt) = (5/72) * 96 = 6.67 = 6px (pixel) 7 = 5.5 lbs = (5.5/72) * 96 = 7.3 = 7px (pixel) 6 = 6.5 lbs = (6.5/72) * 96 = 8.67 = 8px (pixel) 6th = 7.5 lbs = (7.5/72) * 96 = 10px (pixel) 5th = 9 lbs = (9/72) * 96 = 12px (pixel) 5 = 10.5 lbs = (10.5/72) * 96 = 14px (pixel) 4 = 12 lbs = (12/72) * 96 = 16px (pixel) 4 = 14 lbs = (14/72) * 96 = 18.67 = 18px (pixel) small 3 = 15 lbs = (15/72) * 96 = 20px (pixel) 3 = 16 lbs = (16/72) * 96 = 21.3 = 21px (pixel) = 18 lbs = (18/72) * 96 = 24px (pixel) 2 = 22 lbs = (22/72) * 96 = 29.3 = 29px (pixel) Small 1 = 24 lbs = (24/72) * 96 = 32px (pixel) 1 = 26 lbs = (26/72) * 96 = 34.67 = 34px (pixel)

 

6. UIButton details

// The following types of buttons can be defined: // typedef enum {// UIButtonTypeCustom = 0, custom style // UIButtonTypeRoundedRect, rounded rectangle // UIButtonTypeDetailDisclosure, blue Arrow buttons: // UIButtonTypeInfoLight, highlight exclamation point // UIButtonTypeInfoDark, dark exclamation point // UIButtonTypeContactAdd, cross plus button //} UIButtonType;/* forState: the function of this parameter is to define the status in which the text or image of the button appears * // The following are several statuses // enum {// UIControlStateNormal = 0, regular status display // UIControlStateHighlighted = 1 <0, Highlight Status display // UIControlStateDisabled = 1 <1, the disabled status is displayed // UIControlStateSelected = 1 <2, selected status // UIControlStateApplication = 0x00FF0000, when the application flag is enabled, // UIControlStateReserved = 0xFF000000 is reserved for the internal framework, regardless of whether/};/** by default, when the button is highlighted, the color of the image will be painted a little deeper. If this attribute is set to no, * you can remove this function */button1.adjustsImageWhenHighlighted = NO;/* the same as above, by default, when the button is disabled, the image will be painted a little deeper. If NO is set, you can cancel the setting */button1.adjustsImageWhenDisabled = NO;/* the following When the attribute is set to yes, the button will emit light */button1.showsTouchWhenHighlighted = YES; long-press event instance: UIButton * aBtn = [UIButton buttonWithType: UIButtonTypeCustom: CGRectMake (40,100, 60, 60)]; [aBtn setBackgroundImage: [UIImage imageNamed: @ "111.png"] forState: UIControlStateNormal]; // click the button event [aBtn addTarget: self action: @ selector (btnShort :) forControlEvents: UIControlEventTouchUpInside]; // button long press event UILongPressGestu ReRecognizer * longPress = [[UILongPressGestureRecognizer alloc] initWithTarget: selfaction: @ selector (btnLong :)]; longPress. minimumPressDuration = 0.8; // defines the time by [aBtn addGestureRecognizer: longPress];-(void) btnLong :( long *) gestureRecognizer {if ([gestureRecognizer state] = response) {NSLog (@ "Long press event"); UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "Delete Message: @ "are you sure you want to delete this mode? "Delegate: selfcancelButtonTitle: @" cancel "otherButtonTitles: @" delete ", nil]; [alert show];}

 

7: UIApplication knowledge point

UIApplication object. This object is a singleton in iOS. We get it through [UIApplication sharedApplication] and set the number of displayed messages. It is displayed in the upper right corner of the application icon, [UIApplication sharedApplication]. applicationIconBadgeNumber = 9; you can obtain NSIntger x = [UIApplication sharedApplication]. applicationIconBadgeNumber; prevent screen sleep: [UIApplication sharedApplication]. idleTimerDisabled = YES; set the status bar style in app delegate: [UIApplication sharedApplication]. statusBarStyle = UIStatusBarStyleLightContent;

 

8: A countdown code

# Import "ViewController. h "@ interface ViewController () {NSTimer * timer; NSInteger nowSeconds;} @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; nowSeconds = 30*100; // (30 seconds for countdown) timer = [NSTimer scheduledTimerWithTimeInterval: 0.01 target: self selector: @ selector (timerAction) userInfo: nil repeats: YES]; [[nsunloop currentRunLoop] addTimer: timer forMode: nsunloopcommonmo Des];}-(void) didreceivemorywarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} -(void) timerAction {if (nowSeconds <0) {[timer invalidate]; timer = nil; return;} nowSeconds --; if (nowSeconds <= 0) {self. mylable. text = @ "revealing... "; return;} int m = (int) nowSeconds/6000; int s = (int) (nowSeconds/100)-m * 60; NSString * f1 = s> 9? [NSString stringWithFormat: @ "% d", s]: [@ "0" stringByAppendingFormat: @ "% d", s]; int MS = nowSeconds % 100; NSString * f2 = MS> 9? [NSString stringWithFormat: @ "% d", MS]: [@ "0" stringByAppendingFormat: @ "% d", MS]; self. mylable. text = [NSString stringWithFormat: @ "0% d :%@:%@", m, f1, f2] ;}@ end

 

9: Use of BlocksKit plug-ins

Introduce # import <BlocksKit/BlocksKit. h> # import <BlocksKit/BlocksKit + UIKit. h> some common blocks: // view UIView * bcView = [[UIView alloc] init]; bcView. backgroundColor = [UIColor redColor]; bcView. frame = CGRectMake (30, 40, 50, 20); [bcView bk_whenTapped: ^ {NSLog (@ "click to respond");}]; [bcView bk_whenDoubleTapped: ^ {NSLog (@ "double-click response") ;}]; [bcView bk_whenTouches: 1 tapped: 3 handler: ^ {NSLog (@ "Three-click response");}]; [self. view addSubview: bcView]; // Control btn = [[UIButton alloc] initWithFrame: CGRectMake (70, 70, 50, 50)]; [btn setTitle: @ "Save" forState: UIControlStateNormal]; btn. backgroundColor = [UIColor grayColor]; [btn bk_addEventHandler: ^ (id sender) {NSLog (@ "UIControlEventTouchUpInside response"); // judge and remove the response [self defined];} forControlEvents: UIControlEventTouchUpInside]; [self. view addSubview: btn]; // UIAlertView * alertView = [UIAlertView effect: @ "pop-up window effect" message: @ "Hello, select" cancelButtonTitle: @ "cancel" otherButtonTitles: @ [@ "OK", @ "do not want to select"] handler: ^ (UIAlertView * alertView, NSInteger buttonIndex) {if (buttonIndex = 0) {NSLog (@ "");} else if (buttonIndex = 1) {NSLog (@ "");} else {NSLog (@ "select other") ;}}]; [alertView show]; _ block NSInteger total = 0; UIAlertView * otherAlertView = [[UIAlertView alloc] bk_initWithTitle: @ "dynamically Add" message: @ "whether to add"]; NSInteger index1 = [otherAlertView bk_addButtonWithTitle: @ "OK" handler: ^ {total ++; NSLog (@ "% ld", total) ;}]; [otherAlertView. export alertView: Your clickedButtonAtIndex: index1]; [otherAlertView show]; UIAlertView * showAlert = [[UIAlertView alloc] initWithTitle: @ "alertview inherent in the system" message: @ "display information" delegate: self cancelButtonTitle: @ "cancel" otherButtonTitles: nil]; showAlert. bk_cancelBlock = ^ () {NSLog (@ "cancel response") ;}; showAlert. bk_willShowBlock = ^ (UIAlertView * view) {NSLog (@ "show previous response") ;}; showAlert. bk_didShowBlock = ^ (UIAlertView * view) {NSLog (@ "show pop-up window response") ;}; [showAlert show]; // UIActionSheet * myactionSheet = [[UIActionSheet alloc] initWithTitle: @ "display information" delegate: self cancelButtonTitle: @ "cancel" destructiveButtonTitle: @ "display of related content" comment: nil]; myactionSheet. bk_cancelBlock = ^ () {NSLog (@ "select to cancel actionSheet") ;}; [myactionSheet showInView: self. view]; // UITextField * myTextField = [[UITextField alloc] init]; myTextField. backgroundColor = [UIColor yellowColor]; myTextField. frame = CGRectMake (10,130, 80, 20); myTextField. bk_shouldBeginEditingBlock = ^ (UITextField * textField) {NSLog (@ "shouldBeginEditingBlock"); return YES ;}; myTextField. bk_shouldBeginEditingBlock = ^ (UITextField * textField) {NSLog (@ "shouldBeginEditingBlock"); return YES ;}; myTextField. bk_didBeginEditingBlock = ^ (UITextField * textField) {NSLog (@ "didBeginEditingBlock") ;}; myTextField. bk_shouldEndEditingBlock = ^ (UITextField * textField) {NSLog (@ "shouldEndEditingBlock"); return YES ;}; myTextField. bk_didEndEditingBlock = ^ (UITextField * textField) {NSLog (@ "didEndEditingBlock") ;}; myTextField. fields = ^ (UITextField * textField, nsange range, NSString * replacement) {NSLog (@ "shouldChangeCharactersInRangeWithReplacementStringBlock"); return YES ;}; myTextField. bk_shouldClearBlock = ^ (UITextField * textField) {NSLog (@ "shouldClearBlock"); return YES ;}; myTextField. bk_shouldReturnBlock = ^ (UITextField * textField) {NSLog (@ "shouldReturnBlock"); return YES ;}; [self. view addSubview: myTextField];

 

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.