iOS Development Basics-Fragmentation 17

Source: Internet
Author: User

Fundamentals of iOS development-debris 17iOS development fundamentals-Fragmentation 17

1:contentsize, Contentinset and Contentoffset differences

Contentsize is a property in ScrollView that represents a visible area in ScrollView, and if there is a scrollview, its frame is (0,0,320,480), and its contentsize is ( 320,960). That is, this scrollview the entire content size is (320,960), to see (320,480) after the content by sliding scrollview up and down. Contentoffset is the offset of the ScrollView current display area vertex relative to the frame vertex, such as the last example you pulled to the bottom, Contentoffset is (0,-480), that is, y offset 480contentInset Is the relationship between ContentView.frame.origin and Scrollview.frame.origin in ScrollView, such as the frame of Contentview (0,30,320,480), Then the Contentinset is (0, 30), it can also be set up and down around

2:ios Virtual device installation other simulator

Download the DMG installation. Here is the main iOS7.0 simulator offline installation as an example to illustrate, other versions and so on: Download ios_7_0_simulator.dmg after the DMG file, you can see the installation package iphonesimulatorsdk7_0.pkg, Install this installation package by using the installer, which is installed by default on the/platforms/iphonesimulator.platform/developer/sdks/of the selected partition IPHONESIMULATOR7.0.SDK directory, after completely exiting Xcode, copy or move the entire directory that you just installed IPHONESIMULATOR7.0.SDK to/applications/xcode.app/contents/ Developer/platforms/iphonesimulator.platform/developer/sdks directory, (Xcode.app right can "show package Contents") Restarting Xcode will typically be developed and debugged using the appropriate version of the emulator. An easy way to install offline is to copy the previously installed version of Xcode, such as Xcode5.0.2, which is already installed on the iOS emulator, and the directory location is the same, all in xcode.app/contents/developer/. Platforms/iphonesimulator.platform/developer/sdks inside. This will not be necessary to download the offline installation package.

3: Inputaccessoryview and Inputview in the input box

Uitextfields and Uitextview have a Inputaccessoryview attribute that you can set when you want to display a custom view on the keyboard. The view you set is automatically displayed with the keyboard keyboard. It is important to note that your custom view should not be in the other view layers, nor should it be a child view of other views. In fact, your custom view only needs to be assigned to the attribute Inputaccessoryview, so you don't have to do any extra work. Inputview is the keyboard view, when it is nil, the system default keyboard pops up, instance one (how to set a toolbar above the keyboard):-(void) createkeyboardtool{keyboardtool = [[Uitoolbar    Alloc] Initwithframe:cgrectmake (Kzero, Kzero, Kscreenw, 44.0f)];  Nsmutablearray *mytoolbaritems = [Nsmutablearray array]; Create the button above the keyboard toolbar and set the Click event Uibarbuttonitem *cancelbtn = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:    Uibarbuttonsystemitemreply target:self Action: @selector (cancelaction)]; Uibarbuttonitem *space = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemflexiblespace    Target:self Action: @selector (saveaction)]; Uibarbuttonitem *savebtn = [[Uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemdone target:        Self action: @selector (saveaction)];    [Mytoolbaritems ADDOBJECT:CANCELBTN]; [MytooLbaritems Addobject:space];    [Mytoolbaritems ADDOBJECT:SAVEBTN]; Keyboardtool.items = Mytoolbaritems;} Inputaccessoryview: Sets the toolbar displayed at the top of the keyboard; Inputview: custom Keyboard Commenttextview = [[Uitextview alloc]initwithframe:cgrectmake (    Kzero, Kzero, KSCREENW, 200)];    [Commenttextview Becomefirstresponder]; Commenttextview.inputaccessoryview = Keyboardtool; instance two (modify the keyboard view, switch the custom view with the system's own view):/** * Toggle keyboard */-(void) switchkeyboard{/ /Self.textView.inputView = = Nil: Using the system comes with the keyboard if (Self.textView.inputView = = nil) {//switch to a custom emoji keyboard Emtionkeyboa        Rd for a view Self.textView.inputView = Self.emotionkeyboard;    Show Keyboard button Self.toolbar.showKeyboardButton = YES;        } else {//switch to the system's own keyboard Self.textView.inputView = nil;    Show Emoticon button Self.toolbar.showKeyboardButton = NO;        }//Start switching the keyboard this is for fixed self.switchingkeybaord = YES;        Exit keyboard [Self.textview Endediting:yes]; Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (0.1 * nsec_per_sec)), DIspatch_get_main_queue (), ^{//pop-up keyboard, let it slow implementation [Self.textview Becomefirstresponder];    End Toggle Keyboard Self.switchingkeybaord = NO; });} /** * Keyboard frame changes when called (show, hide, etc.) */-(void) Keyboardwillchangeframe: (nsnotification *) notification{//If you are switching the keyboard,        Do not execute the following code if (Self.switchingkeybaord) return;    Nsdictionary *userinfo = Notification.userinfo;    Duration of the animation double duration = [Userinfo[uikeyboardanimationdurationuserinfokey] doublevalue];        Keyboard frame CGRect KEYBOARDF = [Userinfo[uikeyboardframeenduserinfokey] cgrectvalue]; Perform animation [UIView animatewithduration:duration animations:^{//Toolbar Y value = = Keyboard Y value-the height of the toolbar if (Keyboardf.orig IN.Y > Self.view.height) The y value of the {//keyboard has far exceeded the height of the controller view SELF.TOOLBAR.Y = Self.view.height-self.toolbar.height        ;        } else {self.toolbar.y = Keyboardf.origin.y-self.toolbar.height; }    }];}

4: Modify the text in Uisearchbar about Cannel cancellation

-(Uisearchbar *) mysearchbar{if (_mysearchbar==nil) {_mysearchbar=[[uisearchbar alloc]init];        _mysearchbar.showscancelbutton=yes;        _mysearchbar.delegate=self;        [_mysearchbar SizeToFit];        [_mysearchbar setplaceholder:@ "Please enter"];                [_mysearchbar sety:20];                Processing Cannel text display for (ID item in [_mysearchbar Subviews]) {for (id cc in [item Subviews]) {                    if ([Cc Iskindofclass:[uibutton class]]) {UIButton *btn= (UIButton *) cc;                [Btn settitle:@ "Cancel" forstate:uicontrolstatenormal]; }}}} return _mysearchbar;} If it is to get a look, it shows that the cancellation can be set in this delegate:/** * @author Wujunyang, 15-06-24 11:06:44 * * @brief Modify the display text of cancel must first set the Showscancelbutton to Y    ES * @param searchbar < #searchBar description#> */-(void) searchbartextdidbeginediting: (Uisearchbar *) searchbar{    Searchbar.showscancelbutton=yes;        For (ID item in [searchbar Subviews]) {For (ID cc in [item Subviews]) {if ([Cc Iskindofclass:[uibutton class]]) {UIButton *btn= (Uibutto            n *) cc;        [Btn settitle:@ "Cancel" forstate:uicontrolstatenormal]; }        }    }}

There is another way:

-(BOOL) searchbarshouldbeginediting: (Uisearchbar *) searchbar{    SearchController.searchBar.showsCancelButton = YES;    UIButton *cancelbtn = [Searchcontroller.searchbar valueforkey:@ "CancelButton"];    [Cancelbtn settitle:@ "Cancel" forstate:uicontrolstatenormal];    [Cancelbtn settitlecolor:[uicolor colorwithred:14.0/255.0 green:180.0/255.0 blue:0.0/255.0 alpha:1.00] ForState: UIControlStateNormal];    Searchbar.showscancelbutton = YES;    return YES;}

5: push jump and jump back when adding controls to Navigationcontroller

In the child page Navigationcontroller add the control, back to jump when it is not able to self-pin apart, so to manually add a pin in addition to the NAV added control, otherwise the child page of the control will be overlapped on the parent page of the Nav; The following example: in Viewdidload// Load Control    [Self.navigationController.view AddSubview:self.mySearchBar];(void) Viewwilldisappear: (BOOL) Animated {    //This sentence can also be written before    jumping back [Self.mysearchbar Removefromsuperview];    [Super viewwilldisappear:animated];}

6: The entire view is clicked to shrink the keyboard

-(void) viewdidload {    [super viewdidload];    UITapGestureRecognizer *tapgr=[[uitapgesturerecognizer Alloc] initwithtarget:self action: @selector (viewtapped:)];    If you do not have this sentence in the View button, etc. may not trigger the Toucheupinside event    Tapgr.cancelstouchesinview=no;    [Self.view ADDGESTURERECOGNIZER:TAPGR];} -(Ibaction) Btnaction: (ID) Sender {    NSLog (@ "%@", Self.myTextField.text);} -(void) viewtapped: (UITapGestureRecognizer *) tapgr{    [Self.mytextfield resignfirstresponder];} -(void) didreceivememorywarning {    [Super didreceivememorywarning];} @end

7: Call to the third-party plugin for MRC, and engineering for ARC

Set the. m file for the third-party plug-in, project Targets-build phases-compile sources settings-fno-objc-arc some are double stars such as Pltexture **previewtextures; Under Arc, modify it to: Pltexture * __unsafe_unretained *previewtextures;

8: Notification of the way to achieve keyboard shrinkage layout problems

/** * Add toolbar */-(void) setuptoolbar{//1. Add toolbar Iwcomposetoolbar *toolbar = [[Iwcomposetoolbar alloc] init];    Toolbar.delegate = self;    CGFloat Toolbarh = 35;    CGFloat toolbarw = self.view.width;    CGFloat toolbary = Self.view.height-toolbarh;    Toolbar.frame = CGRectMake (0, Toolbary, TOOLBARW, Toolbarh);    [Self.view Addsubview:toolbar];        Self.toolbar = toolbar; 2. Listening keyboard pop-up and hide//keyboard frame (position) is about to change, will issue uikeyboardwillchangeframenotification//keyboard is about to eject, will issue Uikeyboardwillshownoti fication [[Nsnotificationcenter defaultcenter] addobserver:self selector: @selector (keyboardwillshow:) Name:    Uikeyboardwillshownotification Object:nil]; The keyboard is about to be hidden and will issue uikeyboardwillhidenotification [[Nsnotificationcenter Defaultcenter] addobserver:self selector:@ Selector (keyboardwillhide:) name:uikeyboardwillhidenotification Object:nil];} #pragma mark-Keyboard handling/** * Keyboard is about to be hidden */-(void) Keyboardwillhide: (nsnotification *) note{//1. Keyboard pop-up required time cgfloat duration = [Note.userinfo[Uikeyboardanimationdurationuserinfokey] doublevalue];    2. Animation [UIView animatewithduration:duration animations:^{self.toolbar.transform = cgaffinetransformidentity; }];} /** * Keyboard is about to eject */-(void) Keyboardwillshow: (nsnotification *) note{//1. Keyboard pop-up required time cgfloat duration = [Note.userinfo[ui        Keyboardanimationdurationuserinfokey] Doublevalue]; 2. Animation [UIView animatewithduration:duration animations:^{//Remove keyboard height cgrect KEYBOARDF = [Note.userinfo[ui        Keyboardframeenduserinfokey] Cgrectvalue];        CGFloat Keyboardh = keyboardF.size.height;    Self.toolbar.transform = cgaffinetransformmaketranslation (0,-KEYBOARDH); }];} Notification to be sold out-(void) dealloc{[[Nsnotificationcenter Defaultcenter] removeobserver:self];} Note: [Self.textview resignfirstresponder]; give it a look. Changes in input content://2. Listen for changes to the text of the TextView [[Nsnotificationcenter Defaultcente R] Addobserver:self selector: @selector (textchange) name:uitextviewtextdidchangenotification Object:textview];

9: Encapsulates an instance of a Uivew with a button toolbar

. h file Contents: #import <UIKit/UIKit.h> @class iwcomposetoolbar;typedef enum {iwcomposetoolbarbuttontypecamera, Iwcompo Setoolbarbuttontypepicture, Iwcomposetoolbarbuttontypemention, Iwcomposetoolbarbuttontypetrend, IWComposeToolbarB Uttontypeemotion} iwcomposetoolbarbuttontype; @protocol iwcomposetoolbardelegate <NSObject> @optional-(void) Composetoolbar: (Iwcomposetoolbar *) toolbar Didclickbutton: (Iwcomposetoolbarbuttontype) butontype; @end @interface Iwcomposetoolbar:uiview@property (Weak, nonatomic) id<iwcomposetoolbardelegate> delegate; @end. m file contents: #import " IWComposeToolbar.h "@implementation iwcomposetoolbar-(ID) initWithFrame: (cgrect) frame{self = [Super initWithFrame:    Frame]; if (self) {//1. Setting the background Self.backgroundcolor = [Uicolor colorwithpatternimage:[uiimage imagewithname:@ "Compose                _toolbar_background "]; 2. Add button [self addbuttonwithicon:@ "compose_camerabutton_background" highicon:@ "Compose_camerabutton_background_hi GhligHted "Tag:iwcomposetoolbarbuttontypecamera"; [Self addbuttonwithicon:@ "compose_toolbar_picture" highicon:@ "compose_toolbar_picture_highlighted" Tag:I        Wcomposetoolbarbuttontypepicture]; [Self addbuttonwithicon:@ "compose_mentionbutton_background" highicon:@ "Compose_mentionbutton_background_        Highlighted "tag:iwcomposetoolbarbuttontypemention"; [Self addbuttonwithicon:@ "compose_trendbutton_background" highicon:@ "compose_trendbutton_background_highlighted"        Tag:iwcomposetoolbarbuttontypetrend]; [Self addbuttonwithicon:@ "compose_emoticonbutton_background" highicon:@ "Compose_emoticonbutton_background_    Highlighted "tag:iwcomposetoolbarbuttontypeemotion"; } return self;}    -(void) Addbuttonwithicon: (NSString *) icon Highicon: (NSString *) Highicon tag: (iwcomposetoolbarbuttontype) tag{    UIButton *button = [[UIButton alloc] init];    Button.tag = tag;    [Button addtarget:self action: @selector (ButtonClick:) forcontrolevents:uicontroleventtouchupinside]; [Button SetimagE:[uiimage Imagewithname:icon] forstate:uicontrolstatenormal];    [Button Setimage:[uiimage Imagewithname:highicon] forstate:uicontrolstatehighlighted]; [Self Addsubview:button];} /** * Monitor button click */-(void) ButtonClick: (UIButton *) button{if ([Self.delegate respondstoselector: @selector (composetoolbar:    Didclickbutton:)]) {[self.delegate composetoolbar:self DidClickButton:button.tag];        }}-(void) layoutsubviews{[Super Layoutsubviews];    int count = Self.subviews.count;    CGFloat buttonw = Self.width/count;    CGFloat buttonh = self.height;        for (int i = 0; i<count; i++) {UIButton *button = self.subviews[i];        CGFloat Buttonx = buttonw * i;    Button.frame = CGRectMake (Buttonx, 0, buttonw, BUTTONH); }} @end

Basics of iOS development-fragmentation

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.