iOS Learning notes--modal and quartz2d

Source: Internet
Author: User

I. Modal
Default effect of 1.Modal: The new controller drills up from the bottom of the screen until it covers the previous controller; Modal just changed the view of the reality, did not change Rootviewcontroller

2. Common methods
1>. Display the controller in modal form
-(void) Presentviewcontroller: (Uiviewcontroller *) viewcontrollertopresent animated: (BOOL) flag completion: (void (^) ( void)) Completion
2> shut down the modal controller.
-(void) dismissviewcontrolleranimated: (BOOL) flag completion: (void (^) (void)) completion;

3. If a controller is shown in modal form, you can call the controller and the controller's sub-controller to let the controller disappear.

4. Use Cases
1> If the relationship between the controllers is relatively close to the general use of Uinavigationcontroller
2>: If the relationship between the controllers is not very close general use modal

Two. quartz2d
1. Use
1> drawing graphics: lines \ triangles \ rectangles \ Circles \ Arcs, etc.
2> Draw Text
3> draw \ Generate picture (image)
4> read \ Generate PDF
5>.\ cropping a picture
6> custom UI Controls

2. Graphics context
1> is a cgcontextref type of data
2>. Effect:
1). Save drawing information, drawing status
2). Decide where to draw the output target (where to draw?) PDF file, bitmap, or a display window)
3>. The quartz2d provides several types of graphics Context:
1). Bitmap Graphics Context
2). PDF Graphics Context
3). Window Graphics Context
4). Layer Graphics Context
5). Printer Graphics Context

3. Custom View
1>. How to use quartz2d to customize view
First, you have to have a graphical context, because it saves the drawing information and determines where to draw it.
Second, the graphics context must be associated with the view to draw the content to the view
2>. To customize a view
1). Create a new class that inherits from UIView
2). Implement-(void) DrawRect: (CGRect) Rect method, and then in this method
3). Gets the graphical context associated with the current view (in the DrawRect: Method The system has automatically created a layer's graphical context)
4). Draw the appropriate graphic content
5). Render all rendered content to the view using the graphical context

4. Common methods
1> Create a graphics context
Uigraphicsbegin ... ();
2> Get the graphics context
Cgcontextref CTX = Uigraphicsgetcurrentcontext ();
3> render Graphics
Render a hollow shape
Cgcontextstrokepath (CTX);
Render a solid shape
Cgcontextfillpath (CTX);
4> Close Path
Cgcontextclosepath (CTX);
5> setting the graphic color
Cgcontextsetrgbstrokecolor (CTX, 1.0, 0, 0, 1.0);
Cgcontextsetrgbfillcolor (CTX, 1.0, 0, 0, 1.0);
[[Uicolor Purplecolor] setfill];
[[Uicolor Bluecolor] setstroke];
[[Uicolor Greencolor] set]; Recommended Use
6> graphics Context Stack
Save a copy of the graphical context (how many times you need to save the graphics context you want to restore)
Cgcontextsavegstate (CTX);
Restore the graphic context that you started saving
Cgcontextrestoregstate (CTX);
7&gt: A range of content that can be displayed in a specified context
Note that the specified range (that is, the method of pointing cuts must be called before the drawing range), the scope of the available range is after the designation, and the object drawn before the specified clipping range is not affected.
Cgcontextclip (CTX);
8> matrix operations
Note: The set matrix operation must be preceded by the addition of the drawing information
CGCONTEXTROTATECTM (CTX, m_pi_4);
CGCONTEXTSCALECTM (CTX, 0.5, 0.5);
CGCONTEXTTRANSLATECTM (CTX, 0, 150);
9> get Bigmap-made graphics
UIImage *image = Uigraphicsgetimagefromcurrentimagecontext ();

5. Draw the line
If the Uigraphicsgetcurrentcontext method is called in the DrawRect method, the context of the layer is obtained.
Cgcontextref CTX = Uigraphicsgetcurrentcontext ();
Set the starting point
Cgcontextmovetopoint (CTX, 10, 100);
Set End point
Cgcontextaddlinetopoint (CTX, 100, 100);
Set line width
Cgcontextsetlinewidth (CTX, 10);
Styling the start and end points of a line
Cgcontextsetlinecap (CTX, Kcglinecapround);
Style to set the corners of a line
Cgcontextsetlinejoin (CTX, Kcglinejoinround);
Draw a hollow line, draw the line can only be hollow
Cgcontextstrokepath (CTX);

6. Draw Quadrilateral
Get context
Cgcontextref CTX = Uigraphicsgetcurrentcontext ();
Draw Quadrilateral
Cgcontextaddrect (CTX, CGRectMake (10, 10, 150, 100));
Render a graphic onto a layer
Cgcontextstrokepath (CTX);
Cgcontextfillpath (CTX);

7. Draw circles and arcs
//Get context
Cgcontextref CTX = Uigraphicsgetcurrentcontext ();
Draw Arc
Cgcontextaddarc (CTX, 100, 0), m_pi_2, M_PI, 100 Center, 50 radius, m_pi_2 start Radian, M_pi end Radian, clockwise draw arc Direction (0 clockwise, 1 counterclockwise)
//Draw ellipse
Cgcontextaddellipseinrect (CTX, CGRectMake (s), (a) (at the beginning of the OC coordinate system);
Draw a circle
//First
Cgcontextaddarc (CTX, 0, 2 * m_pi, 0);
The second type of
Cgcontextaddellipseinrect (CTX, cgrectmake);
Renders the graphic to
Cgcontextstrokepath (CTX) on the layer;
Cgcontextfillpath (CTX);

7. Drawing text
NSString *str = @ "good weather";
Nsmutabledictionary *MD = [Nsmutabledictionary dictionary];
Set Text color
Md[nsforegroundcolorattributename] =[uicolor Redcolor];
Set Text background color
Md[nsbackgroundcolorattributename] = [Uicolor greencolor];
Set Text Size
Md[nsfontattributename] = [Uifont systemfontofsize:20];
Draw text to the point where you are pointing
[Str drawatpoint:cgpointmake (Ten) WITHATTRIBUTES:MD];
Draws text to a specified range, and does not appear when the text is out of range if the line does not fit automatically
[Str drawinrect:cgrectmake (Withattributes:nil];

8. Drawing pictures
UIImage *image = [UIImage imagenamed:@ "BG"];
Drawing a picture onto a layer using the OC method
Draws a picture to the specified location
[Image drawatpoint:cgpointmake (0, 0)];
Use the Drawinrect method to draw the image to layer by stretching the original image
[Image drawinrect:cgrectmake (0, 0, 200, 200)];
Use the Drawaspatterninrec method to draw the image to layer by tiling the original image
[Image drawaspatterninrect:cgrectmake (0, 0, 320, 480)];

Three. Touch events
Events in iOS can be divided into 3 major types
1> Touch Event
2> Accelerometer Events
3> Remote control events

1. Responder Object
Not all objects in iOS can handle events, only objects that inherit Uiresponder can receive and handle events. We call it "responder object."
UIApplication, Uiviewcontroller, and UIView inherit from Uiresponder, so they are both responder objects that can receive and handle events

2.UIResponder
Uiresponder internally provides the following methods to handle events
1> Touch Event
-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event;
-(void) touchesmoved: (Nsset *) touches withevent: (Uievent *) event;
-(void) touchesended: (Nsset *) touches withevent: (Uievent *) event;
-(void) touchescancelled: (Nsset *) touches withevent: (Uievent *) event;
2> Accelerometer Events
-(void) Motionbegan: (uieventsubtype) Motion withevent: (uievent *) event;
-(void) motionended: (uieventsubtype) Motion withevent: (uievent *) event;
-(void) motioncancelled: (uieventsubtype) Motion withevent: (uievent *) event;
3> Remote control events
-(void) Remotecontrolreceivedwithevent: (Uievent *) event;

3.UIView Touch Event handling: Four ways to re-uiresponder touch events
1> Touch start: One or more fingers start to touch the view, the system automatically calls the following method of the view
-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event
2> Touch move: One or more fingers moving on the view, the system automatically calls the view's following method (as the finger moves, The method is called continuously)
-(void) touchesmoved: (Nsset *) touches withevent: (Uievent *) event
3> Touch ends: One or more fingers leave the view, The system automatically calls the following method of view
-(void) touchesended: (Nsset *) touches withevent: (Uievent *) event
4> touch Cancel (May experience): Before Touch ends, A system event, such as a phone call, interrupts the touch process, and the system automatically calls the following method of view
-(void) touchescancelled: (Nsset *) touches withevent: (Uievent *) Event
5>.4 Touch Event Handling methods, there are Nsset *touches (both of which are Uitouch objects) and uievent *event two parameters
1). During a complete touch process, only one event object is generated, 4 Touch methods are the same event parameter
2). If two fingers touch a view at the same time, the view calls only once Touchesbegan:withevent: method, the touches parameter is loaded with 2 Uitouch objects
3). If these two fingers touch the same view one after the other, then view calls 2 times Touchesbegan:withevent: Method, and the touches parameter in each call contains only one Uitouch object
4). Depending on the number of Uitouch in touches, you can tell whether it's a single touch or a multi-touch

.

4.UITouch
1> When the user touches the screen with a finger, a Uitouch object associated with the finger is created; one finger corresponds to a Uitouch object; Began:,moved: and ended: The Uitouch object saved by one finger is the same as
2>. Effect
1). Holds the information related to the finger, such as the position of the touch, the time, the stage
2). When the finger moves, The system updates the same Uitouch object so that it can hold the finger at the touch position
3). When the finger leaves the screen, the system destroys the corresponding Uitouch object
3> Common Properties and Methods
1). The window at which the touch was generated: @ Property (Nonatomic,readonly,retain) UIWindow *window;
2). The view at which the touch was generated: @property (nonatomic,readonly,retain) UIView *view;
3). Tap the number of times in a short period of time, you can judge by Tapcount click, double click or more click: @property (nonatomic,readonly) Nsuinteger Tapcount; Note: To avoid using double-click or more click events in Mobile Development
4). Records the time when the touch event was generated or changed, in seconds: @property (nonatomic,readonly) nstimeinterval timestamp;
5). The status of the current touch event: @property (nonatomic,readonly) uitouchphase phase;
6).-(Cgpoint) Locationinview: (UIView *) view; The return value represents the position of the touch on the view, where the position returned is for the view's coordinate system (the origin (0, 0) in the upper-left corner of the view), and the return of the view parameter to nil when called, and returns the position of the touch point at UIWindow
7).-( Cgpoint) Previouslocationinview: (UIView *) view; This method records the position of the previous touch point

5.UIEvent
1> each occurrence of an event produces a Uievent object; Uievent: Called an event object to record the time and type of event generation
2>. Common Properties
1). Event Type: @property (nonatomic,readonly) uieventtype type;
2). Event Subtype: @property (nonatomic,readonly) Uieventsubtype subtype;
3). Time generated by the event: @property (nonatomic,readonly) nstimeinterval timestamp;

6.UIView does not receive three cases of touch events
1&GT: Do not receive user interaction userinteractionenabled = no
2&gt: Hide hidden = YES
3> transparent alpha = 0.0 ~ 0.01
Tip: Uiimageview's userinteractionenabled default is no, so Uiimageview and its child controls cannot receive touch events by default.
7. Gesture Recognizer----Uigesturerecognizer
1>. Uigesturerecognizer is an abstract class that defines the basic behavior of all gestures and uses its subclasses to handle specific gestures
1). UITapGestureRecognizer (percussion)
2). Uipinchgesturerecognizer (pinch, for zooming)
3). Uipangesturerecognizer (drag)
4). Uiswipegesturerecognizer (Swipe)
5). Uirotationgesturerecognizer (swivel)
6). Uilongpressgesturerecognizer (Long Press)
2>. UITapGestureRecognizer Steps to use
1). Create a gesture Recognizer object
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
2). Set the specific properties of the gesture Recognizer object
2 consecutive strokes
tap.numberoftapsrequired = 2;
It takes 2 fingers to tap together.
tap.numberoftouchesrequired = 2;
3). Add the gesture recognizer to the corresponding view
[Self.iconview Addgesturerecognizer:tap];
4). Trigger of the monitor gesture
[Tap addtarget:self Action: @selector (Tapiconview:)];
3>. Status of Gesture recognition
typedef ns_enum (Nsinteger, uigesturerecognizerstate) {
No touch event occurs, default state of all gesture recognition
Uigesturerecognizerstatepossible,
When a gesture has started but has not changed or completed
Uigesturerecognizerstatebegan,
Gesture State Change
Uigesturerecognizerstatechanged,
Gesture Completion
Uigesturerecognizerstateended,
Gesture cancellation, revert to possible state
Uigesturerecognizerstatecancelled,
Gesture failed to revert to possible state
Uigesturerecognizerstatefailed,
Recognition to gesture recognition
uigesturerecognizerstaterecognized = uigesturerecognizerstateended
};

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.