IOS development-UI (7) view-level animation and ImageView,-uiimageview

Source: Internet
Author: User

IOS development-UI (7) view-level animation and ImageView,-uiimageview

Knowledge point:

1. simple animation of UIView

2. UIView hierarchy

3. Use of UIImageView

4. UIView dock Mode

 

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

Simple animation of UIView

 

1. UIView Coordinate System

1) Coordinate System of UIView relative to parent View

 

2. frame, center, and bounds relationships of UIView

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

Bounds: the position and size of the view in the local coordinate system. (The reference point is the local coordinate system)

Center: the center of the view in the parent view coordinate system. (The reference point is the father's coordinate system)

 

3. Set transparency

@ Property (nonatomic) CGFloat alpha

View1.alpha = 0.2;

4. simple animation effect 1 in UIView

1. Start Animation

+ (Void) beginAnimations :( NSString *) animationID context :( void *) context;

2. Duration

+ (Void) setAnimationDuration :( CFTimeInterval) dur;

3. Submit an animation (run an animation)

+ (Void) commitAnimations;

 

// Enable the animation

[UIView beginAnimations: nil context: nil];

// Set the animation duration

[UIView setAnimationDuration: 5.0];

// Submit an animation

[UIView commitAnimations];

 

5. simple animation effect 2 in UIView

+ (Void) animateWithDuration :( NSTimeInterval) duration

Animations :( void (^) (void) animations

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

// Start the animation [UIView animateWithDuration: 2.0 animations: ^ {// submitted animation content // change the position of view1 view1.center = CGPointMake (CGRectGetWidth (self. window. frame)-50, CGRectGetHeight (self. window. frame)-50); // change the green view1.backgroundColor = [UIColor greenColor];} completion: ^ (BOOL finished) {// After the preceding animation is executed, the code block in the block will be called back. // enable the animation [UIView animateWithDuration: 2.0 animations: ^ {// restore the original view1.center = CGPointMake (50, 70 ); view1.backgroundColor = [UIColor orangeColor] ;}];

 

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

UIView hierarchy

 

1. How to add a new UIView to the UIView

-(Void) addSubview :( UIView *) view;

[Self. window addSubview: view1];

 

2. How to obtain the parent view of UIView

@ Property (nonatomic, readonly) UIView * superview;

// Obtain its parent view object from the Child View

NSLog (@ "sView3.superview = % p fView = % p", sView3.superview, fView );

 

3. How to obtain the UIView subview

@ Property (nonatomic, readonly, copy) NSArray * subviews; // obtain all the child views above the parent View

For (UIView * tempView in fView. subviews)

 

4. Move a subview to the frontend

-(Void) bringSubviewToFront :( UIView *) view;

// Move a subview to the frontend

[FView bringSubviewToFront: sView1];

// Move a subview to the end

[FView sendSubviewToBack: sView2];

 

5. Swap the layer of the Child View

-(Void) exchangeSubviewAtIndex :( NSInteger) index1 withSubviewAtIndex :( NSInteger) index2;

// Swap the layers of a Connected View

[FView exchangeSubviewAtIndex: 0 withSubviewAtIndex: 2];

 

6. How to insert a view in a specific position

-(Void) insertSubview :( UIView *) view atIndex :( NSInteger) index;

// Insert View

[FView insertSubview: sView4 atIndex: 1];

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

-(Void) removeFromSuperview;

Ps: removeFromSuperview: removes a view from the parent view and removes all child views from the view.

// Delete All subviews in this view at one time

[TempView removeFromSuperview];

 

8. How to cut a view that exceeds the parent View

@ Property (nonatomic) BOOL clipsToBounds;

// Cut the part that exceeds the parent View

FView. clipsToBounds = YES;

 

9. How to hide and display a UIView

@ Property (nonatomic, getter = isHidden) BOOL hidden;

// Hide a view

SView1.hidden = YES;

10. Check the relationship between views.

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

 

// Checks whether a view is a subview of another view.

If ([sView2 isDescendantOfView: fView]) {

NSLog (@ "sView2 is the Child view of fView ");

}

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

Use UIImageView

1. How to reset the image content

@ Property (nonatomic, retain) UIImage * image

2. How to solve the problem of image content deformation (this attribute is inherited by UIView)

@ Property (nonatomic) UIViewContentMode contentMode

UIViewContentModeScaleToFill: The content is stretched, causing content deformation.

UIViewContentModeScaleAspectFit: The content is stretched, and the content proportion remains unchanged.

UIViewContentModeScaleAspectFill: The content is stretched, and the content proportion remains unchanged. However, some content may not be displayed.

ImageView. contentMode = UIViewContentModeScaleAspectFill;

 

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

Simple Gesture operations

 

UITapGestureRecognizer click

UIPinchGestureRecognizer 2 refers to the scaling that is usually used to move inside or out.

UIRotationGestureRecognizer Rotation

UISwipeGestureRecognizer slide for Fast movement

UIPanGestureRecognizer dragging and slow moving

UILongPressGestureRecognizer

 

/* Parameter 1: target object parameter 2: callback Method */UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (myTap :)]; // double-click to trigger the tap. numberOfTapsRequired = 2; // Add the gesture to the Window above [self. window addGestureRecognizer: tap]; // slide quickly * swi = [[delealloc] initWithTarget: self action: @ selector (myTap :)];/* typedef NS_OPTIONS (NSUInteger, iterator) {uiswipegesturerecognizerdireright = 1 <0, uiswipegesturerecognizerdireleft = 1 <1, expires = 1 <2, expires = 1 <3 }; * /// set the supported direction. // either the horizontal or vertical direction supports swi. direction = uiswipegesturerecognizerdireup up | UISwipeGestureRecognizerDirectionDown; [self. window addGestureRecognizer: swi]; // long-pressed gesture // after long-pressed, sliding will also be triggered, and dropping will also trigger a timer * longGes = [[UILongPressGestureRecognizer alloc] initWithTarget: self action: @ selector (myTap :)]; // the shortest time required to trigger the event longGes. minimumPressDuration = 1; [self. window addGestureRecognizer: longGes]; // disable the Human-Computer Interaction switch // self. window. userInteractionEnabled = NO;/* Note: 1. each UIView has a property userInteractionEnabled. If the property value is NO, an event (including a gesture and btn Click Event) cannot be triggered. UILabel: When UIImageView is instantiated, the default value of userInteractionEnabled is NO 3. if the value of userInteractionEnabled in the parent view is NO, the Child view cannot respond to event 4. if a view is hidden, it cannot respond to events */ps: When the view hidden attribute is set to YES or userInteractionEnabled = NO, human-machine interaction cannot be performed.

 

 

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

UIView dock Mode

 

1. Automatic Layout: How does the child view change when the parent view changes?

1) set the autoresize attribute of the parent view to YES.

2) set the mask attribute of the subview.

// Set the dock Mode

// Set autoresizesSubviews for the parent View

FView2.autoresizesSubviews = YES;

// Set the dock mode for the subview

// The distance from the UIViewAutoresizingFlexibleLeftMargin subview to the right of the parent view is fixed.

// The width of UIViewAutoresizingFlexibleWidth is variable.

SView2.autoresizingMask = UIViewAutoresizingFlexibleWidth;

 

@ Property (nonatomic) BOOL autoresizesSubviews;

 

@ Property (nonatomic) UIViewAutoresizing autoresizingMask;

UIViewAutoresizingNone

Is not automatically adjusted.

UIViewAutoresizingFlexibleLeftMargin

The distance between the left side of the superView is automatically adjusted to ensure that the distance to the right side of the superView remains unchanged. UIViewAutoresizingFlexibleRightMargin

The distance to the right of superView is automatically adjusted to ensure that the distance to the left of superView remains unchanged. UIViewAutoresizingFlexibleTopMargin

The distance between the superView and the top of the superView is automatically adjusted to ensure that the distance from the bottom of the superView remains unchanged. UIViewAutoresizingFlexibleBottomMargin

The distance from the superView bottom is automatically adjusted to ensure that the distance from the superView top remains unchanged. UIViewAutoresizingFlexibleWidth

Automatically adjust the width of the superView to keep the distance from the left and right of the superView. UIViewAutoresizingFlexibleHeight

The height is automatically adjusted to keep the distance from the top and bottom of the superView unchanged.

 

Related Article

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.