Knowledge Point 5

Source: Internet
Author: User

Because it is a custom component so storyboard we can't use, all the code must be handwritten, so as to ensure the flexibility of the use of components and reduce the coupling between the various components, more conducive to cooperation between the team. When encapsulating a component, it is necessary to reserve an interface that the outside world can use, and return the returned data.

-(Instancetype) init

{

self = [super init];

if (self) {

}

return self;

}

Save used images in SQLite

NSData *imagedata = uiimagepngrepresentation (image);

[Copy_self.imagemode Save:imagedata Imagetext:imagetext];

@property (nonatomic,readwrite) cllocationcoordinate2d coordinate;

Cocoapods should be the most commonly known class Library management tool for iOS, and can be used to manage these third-party libraries conveniently and centrally.

Installing cocoapods requires a ruby environment

The Mac OS itself comes with Ruby, but it still updates the insurance,

App directory: appdelegate : This directory is a AppDelegate.h (. m) file, which is the entry file for the entire application, so take it out separately.

Macro : This directory has a macro definition that will be used by the entire application.

Macro

| - AppMacro.h: app - related macro definition

|-NotificationMacro.h: put a notification-related macro definition

|-VendorMacro.h: put some third-party constants

|-UtilsMacro.h: There are some handy macro definitions

Vendors : This directory is placed in a third-party class library/SDK

Resources : This directory is a list of resources that the app will use, mostly pictures

KVO is the basis for implementing the cocoa bindings, which provides a way for the corresponding objects to be notified when a property is changed how is this implemented? In fact, this is achieved through OBJECTIVE-C's powerful runtime.

Run time (runtime):

-(void) Parseobject: (ID) Object {

For (ID data in object) {

if ([[Data Type] isequaltostring:@ "String"]) {

[self parsestring:[data value]];

} else if ([[Data type] isequaltostring:@ "number"]) {

[self parsenumber:[data value]];

} else if ([[Data Type] isequaltostring:@ "Array"]) {

[self parsearray:[data value]];

}

}

}

-(void) Parseobjectdynamic: (ID) Object {

For (ID data in object) {

[Self performselector:nsselectorfromstring ([NSString stringwithformat:@ "parse%@:", [Data type]]) withobject:[data Value]];

}

}

-(void) parsestring: (NSString *) astring {}

-(void) Parsenumber: (NSString *) anumber {}

-(void) Parsearray: (NSString *) Aarray {}

The method consists of two parts. Selector equivalent to a method of id;imp is the implementation of the method. One of the conveniences of such separation is that the correspondence between selector and IMP can be changed. For example, an IMP can have multiple selectors pointing to it. IMP is a pointer to a method implementation

Let's use block as IMP, and the snippet below shows how to add a new method using block.

IMP myimp = Imp_implementationwithblock (^ (id _self, nsstring *string) {

NSLog (@ "Hello%@", string);

});

Class_addmethod ([MYclass class], @selector (SayHello:), Myimp, "[Email protected]:@");

The Core graphics is a set of APIs for drawing 2D graphics

The Core animation is included in Quartzcore.framwork, a set of more freedom graphics and animation APIs,

The Core image is a set of APIs for image, video processing, such as adding filters.

In iOS, all uiview have their own calayer (accessed via Uiview.layer), and UIView's rendering and animations are eventually implemented through layers. In this sense, UIView is a simple shell that passes the information needed for drawing to a layer. Of course UIView also has an important function of handling events, such as clicking buttons, swiping, and so on.

So the General animation view animation can be dealt with.

The focus is on modular programming multi-use combination, less use of inheritance; modular programming Benefits: As long as the interface is right, and the function is normal, each module as long as the completion of its own function on the line, out of the question, but also only need to adjust a module, without worrying about the other modules will cause the abnormal function.

Modules are mutually blind, a module does not need to know the existence of the B module, but also can not rely on the B module, so as to decouple (in this case, in fact, often naturally unnatural to a module coupling). The module only needs to provide the interface for the mother to use the line. Of course, when a particular event occurs, it is also necessary to notify the mother, which requires the use of delegate.

Using inheritance complicates the architecture, and in order to ensure that each class has only the methods it needs, it needs to be very careful to define the Public/protected/private method, especially if you need to be cautious about changing the parent class, which is difficult to cope with in a volatile environment.

Use combination can let each module focus on its own function, on-demand use, the module adjustment as long as not affect the interface, love how to toss on how to toss, enhance freedom.

But the combination also has side effects, especially when it comes to sub-modules, such as the above ballcomponent, need to redefine the interface, and inherit the words do not have this problem. There are some common properties and methods that can be implemented by inheritance, such as all component inherit from Basecomponent.

So use the combination as much as possible, and use less inheritance.

To hide the methods we use for the control and control callbacks, we declare our controls and methods in viewcontroller.m with an extension.

Add ImageView to the bottom of the view

[Self.view InsertSubview:self.backView atindex:0];

Change in audio/video player time (method of timer execution)

-(void) time

{

Total time to get audio

Nstimeinterval Totaltimer = self.player.duration;

Gets the current time of the audio

Nstimeinterval currenttime = self.player.currentTime;

To set the progress of a progress bar based on time

Self.progress.progress = (Currenttime/totaltimer);

Convert seconds to minutes

int CURRENTM = CURRENTTIME/60;

CurrentTime = (int) CurrentTime ';

int totalm = TOTALTIMER/60;

Totaltimer = (int) Totaltimer ';

Show the time on the lable

NSString *timestring = [NSString stringwithformat:@ ". 0f:.0f|. 0f:.0f ", Currentm, CurrentTime, Totalm,totaltimer];

Self.label.text = timestring;

}

Here are some ways iOS provides a way to manage a child view, which is commonly used as follows:

(1) initWithFrame: Through frame initialization view, parameters are CGRectMake (x, y, width, height);

(2) Insertsubview:atindex: Inserts a view toward the specified layer, which view calls the method, and index is relative to WHO.

(3) Insertsubview:abovesubview: Inserts a child view on a view.

(4) Insertsubview:belowsubview: Add a new view after a child view

(5) Bringsubviewtofront: Put the handle view to the front

(6) Sendsubviewtoback: Put the handle view to the last

(7) Exchangesubviewatindex:withsubviewatindex: Swap two views in front and back order

(8) Removefromsuperview: Remove View from parent view

(9)-(void) Addsubview: (UIView *) view Add a

The hierarchy of views is distinguished by index, which increments from 0 with step 1, and index 0 represents the lowest level in the view hierarchy.

Get Viewcontroller created by storyboard:

Get Storyboard: Use Bundles to get our storyboard based on storyboard's name,

Uistoryboard *story = [Uistoryboard storyboardwithname:@ "Main" Bundle:[nsbundle Mainbundle]];

by storyboard, according to MyView's Storyboardid, to get the view we want to switch.

Uiviewcontroller *myview = [Story instantiateviewcontrollerwithidentifier:@ "MyView"];

From Navigationcontroller to the view we want to push

[Self.navigationcontroller Pushviewcontroller:myview Animated:yes];

There is only one navigationbar in a navigationcontroller, and each viewcontroller under a navigationcontroller has its own navigationbaritem.

Add a button to the right

One self.navigationItem.rightBarButtonItem = item1;

12

13//Add two buttons to the right

Self.navigationItem.rightBarButtonItems = @[item1, item2];

CoreData configuration and use of the steps are quite complicated, so try to use less;

How to log the user's login status? Just use Nsuserdefault. Nsuserdefault to synchronize after setting the value Nsuserdefault is a class that Apple provides to us to store the user's login information, which is, of course, persistent.

Get Userdefaults single case

Nsuserdefaults *userdefaults = [Nsuserdefaults standarduserdefaults];

Removing user information stored in the Userdefaults

[Userdefaults removeobjectforkey:@ "name"];

[Userdefaults removeobjectforkey:@ "password"];

[Userdefaults Synchronize];

Knowledge Point 5

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.