Stanford iOS7 Open Class 7-9 notes and Demo, Stanford ios7 Open Class 7-9
This section mainly introduces iOS graphics, gestures, protocols, blocks, special mechanical effects animation (including gravity, collision, adsorption, etc.) and automatic layout content.
1. Drawing and gesture
(1) When calling a custom UIView, you can use the awakeFromNib Method for initialization.
(2) common measurement units for drawing in iOS:
CGFloat: floating point value, same as float;
CGPoint, CGSize, and CGRect are the three structures that represent the store described by youxy coordinates, the size value described by the width and height, and the rectangle described by the origin coordinates and width and height. The measurement units are CGFloat.
(3) There is a drawRect method in the Custom UIView implementation file, which provides an entrance for us to re-draw the UIView and update our UIView by rewriting this method, however, Apple requires developers to use the setNeedsDisplay method to notify the system to call drawRect for re-painting, rather than directly calling it.
(4) iOS provides the UIBezierPath class for developers to construct and draw images through straight lines or curves.
(5) Coordinate System reference when drawing a drawing. The origin is in the upper left corner, bounds refers to the coordinate system composed of the rectangle of the View, and frame refers to the coordinate system composed of the outsourcing rectangle of the View, the center Coordinate refers to the coordinate value of the center of the View in the coordinate system of the parent View.
(6) gesture: The system has encapsulated the gesture and can be used directly. Two methods are available:
One is to add a gesture to the Interface Builder, connect it to the implementation file, and then process the gesture. We can further use the process to find out where the setting is not complete, when using the auxiliary window to modify the storyboard and the Standard Single Window to modify the storyboard, the modification results are not synchronized, and finally the modifications are manually modified. Pay attention to this.
Another method is to add it directly in the code, and add addGestureRecognizer in advance (for example, in ViewDidLoad) to specify the gesture Response Function and implement the function method.
(7) For gesture states, they are divided into discontinuous gestures and continuous gestures. Discontinuous gestures, such as clicking a gesture Tap, have only one status Recognized, which indicates the moment the screen is touched, It is Recognized. For discontinuous gestures such as pinch, the gestures are in the Began, Failed, Changed, and Cancelled statuses. These statuses are critical to implementing the gesture processing method. When the gesture has started to be executed, the gesture must be processed in the changed state. In some special cases, for example, when you use a gesture, the phone will enter the Cancelled status.
Ii. Protocol, Block, and animation with special mechanical effects
(1) protocol, iOS provides specific methods for different objects. Of course, if you want to use these methods, you also need to declare them in the prescribed format, which is somewhat similar to the interface function, some interfaces are provided in advance for developers to use, and the proxy delegate is specified so that the proxy can implement the methods provided in the Protocol, for example, the dynamicAnimatorDidPause method provided by the UIDynamicAnimatorDelegate protocol is used in the Demo (triggered when the mechanical behavior is interrupted), and a custom method is called in it, this function is used to remove an object when it is full.
Of course, you can also customize the Protocol as needed, such as jump between two pages, especially when you need to jump to the page to transfer a value, you can also pass the value as a parameter in the Protocol method.
(2) Block, code Block, a bit similar to the anonymous function of C.
When using a block, pay attention to the retain cycle problem. For example, if a block in the Demo is directly used internally, a strong pointer will exist between the block and self, therefore, neither of them can be destroyed. Therefore, weakSelf must be referenced weakly to replace self.
(3) view animation. iOS provides some encapsulated view animation effects for developers to directly use.
(4) special mechanical effects animation. Many effects have been encapsulated in iOS. Gravity, collision, and adsorption Effects are used in the Demo. The usage is as follows:
First, create a container UIDynamicAnimator for animation execution. The ReferenceView represents the animation in that view, which is equivalent to the mechanical Reference System in physics.
Describes the specific mechanical effects to specify the behavior,
Specifies the object for executing the animation effect (dropBehavior here combines the action of gravity and Collision Effect)
Iii. Automatic Layout
Xcode provides an automatic layout mechanism for some simple interfaces. By adding some constraints, you can handle the interface display effects after different sizes and screen rotation.
Results Before and After Automatic Layout (constraints already added:
Demo effect ,:Http://files.cnblogs.com/colinhou/Dropit.zip