UI Basics--(4) UIView deep Understanding, Uiimageview animations and gestures

Source: Internet
Author: User

Knowledge Points:

Simple animation of 1.UIView

1.UIView Hierarchical relationships

Use of 2.UIImageView

3.UIView Docking Mode

=====================

UIView's Simple animations

1.UIVew coordinate system

1) UIView coordinate system relative to the parent view

Frame,center,bounds Relationship of 2.UVIew

Frame: The position and size of the view in the parent view coordinate system. (reference point is, Father's coordinate system)

Bounds: The position and size of the view in the local coordinate system. (Reference point Yes, local coordinate system)

Center: The location of the view's central point in the parent view coordinate system. (reference point is, Father's coordinate system)

3. Setting transparency

@property (nonatomic) cgfloat Alpha

Simple animation effect in 4.UIView 1

1. Start the animation

+ (void) Beginanimations: (NSString *) Animationid context: (void *) context;

2. Duration

+ (void) Setanimationduration: (Cftimeinterval) dur;

3. Commit animation (run animation)

+ (void) commitanimations;

5. Simple animation effect in UIView 2

+ (void) Animatewithduration: (nstimeinterval) duration

Animations: (void (^) (void)) animations

Completion: (void (^) (BOOL finished)) completion

Exercise: Moving a square view of 100 from (0,0) to (100,100) and then arriving at an instant from

(100,100) move to (0,0), request to use animation effect.

=====================

UIView Hierarchy Relationship

1. How to overlay the new UIView on the Uview

-(void) Addsubview: (UIView *) view;

2. How to get the parent view of UIView

@property (nonatomic,readonly) UIView *superview;

3. How to get UIView sub-view, insert order

@property (nonatomic,readonly,copy) Nsarray *subviews;

4. Move a sub-view to the front

-(void) Bringsubviewtofront: (UIView *) view;

5. Swap the location of the child view

-(void) Exchangesubviewatindex: (Nsinteger) index1 Withsubviewatindex: (Nsinteger) Index2;

6. How to insert a view in a specific location

-(void) Insertsubview: (UIView *) View Atindex: (nsinteger) index;

7. How to delete a view (the function is sent to the view to be deleted)

-(void) Removefromsuperview;

Ps:removefromsuperview: Removes a view from the parent view and removes all the child views on that view

8. How to cut a view beyond the parent view

@property (nonatomic) BOOL clipstobounds;

9. How to hide and show a UIView

@property (Nonatomic,getter=ishidden) BOOL hidden;

9. Detecting the relationship between views

-(BOOL) Isdescendantofview: (UIView *) view;

=====================

Uiimageview use

1. How to re-set the image content

@property (nonatomic,retain) UIImage *image

2. How to solve the image content distortion problem (this property is inherited by UIView)

@property (nonatomic) Uiviewcontentmode Contentmode

Uiviewcontentmodescaletofill stretching content, causing content to deform

Uiviewcontentmodescaleaspectfit stretched content, content scale unchanged

Uiviewcontentmodescaleaspectfill stretched content, content scale unchanged, but it is possible that some content cannot be displayed

Exercise: Switch the display of 4 images back and forth with 2 buttons

3. Simple gesture operation

UITapGestureRecognizer Click

Uipinchgesturerecognizer two refers to the inward or outward toggle, usually used in the zoom

Uirotationgesturerecognizer rotation

Uiswipegesturerecognizer Slide, fast moving

Uipangesturerecognizer drag, slow move

Uilongpressgesturerecognizer Long Press

PS: When the View hidden property is set to Yes, or userinteractionenabled=no

, there is no human-computer interaction.

Add gestures (three-step)

First create a ImageView (add a gesture to ImageView), and then add

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initwithtarget:self Action: @selector (Clik)];

[ImageView Addgesturerecognizer:tap];

imageview.userinteractionenabled = YES; Remember to open the interaction

4. Animations

Note: Uiimageview albums have an animated effect setanimationimages

[ImageView Setanimationimages:imagearray];

=====================

UIView Docking Mode

1. Auto layout: How the child view changes when the parent view changes

1) First set the AutoResize property of the parent view to Yes

2) Set the Mask property of the child view again

@property (nonatomic) BOOL autoresizessubviews;

@property (nonatomic) uiviewautoresizing autoresizingmask;

Uiviewautoresizingnone

is not automatically adjusted.

Uiviewautoresizingflexibleleftmargin

Automatically adjusts the distance to the left of the superview to ensure that the distance to the right of the Superview is constant uiviewautoresizingflexiblerightmargin

The right distance from the Superview is automatically adjusted to ensure that the distance to the left of the Superview is constant. Uiviewautoresizingflexibletopmargin

Automatically adjusts the distance from the top of the Superview to ensure that the distance from the bottom of the Superview is constant. Uiviewautoresizingflexiblebottommargin

Automatically adjusts the distance from the bottom of the superview to ensure that the distance from the top of the Superview is constant. Uiviewautoresizingflexiblewidth

Automatically adjusts its width to ensure that the distance to the left and right of the Superview is constant. Uiviewautoresizingflexibleheight

Automatically adjusts its height to ensure that the distance from the top and bottom of the Superview is constant.

UI Basics--(4) UIView insight, Uiimageview animations and gestures

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.