UIView and uiview Animation
/*
Layer relationship
Child view-view nested on parent View
Parent view-nested View
The view and view can be nested layer by layer
*/
UIView * red = [[UIView alloc] initWithFrame: CGRectMake (50,100,100,100)];
Red. backgroundColor = [UIColor redColor];
// 1. Nest A subview on the parent View
[Self. window addSubview: red];
// 2. How to obtain the parent view (only one)
UIView * window = [red superview];
// You can know through the same address, which is the same window
NSLog (@ "% p", self. window );
NSLog (@ "% p", window );
// 3. Obtain the subview (multiple subviews can be obtained) [note] the returned value is an array.
NSArray * subViews = [self. window subviews];
NSLog (@ "% lu", [subViews count]);
// 4. delete a view
// [Red removeFromSuperview];
UIView * blue = [[UIView alloc] initWithFrame: CGRectMake (60,110,100,100)];
Blue. backgroundColor = [UIColor blueColor];
[Self. window addSubview: blue];
// 5. Place a view in front of the parent View
// [Self. window bringSubviewToFront: red];
// 6. Place a view behind the parent View
// [Self. window sendSubviewToBack: blue];
UIView * yellow = [[UIView alloc] initWithFrame: CGRectMake (70,120,100,100)];
Yellow. backgroundColor = [UIColor yellowColor];
// You can add the yellow View to the window using the following four methods:
// [Self. window addSubview: yellow];
// 7. Insert a view behind a view
// [Self. window insertSubview: yellow belowSubview: red];
// 8. Insert a view before a view
// [Self. window insertSubview: yellow aboveSubview: red];
// 9. Insert at the specified position using subscript
// The coordinate index is counted from the internal
[Self. window insertSubview: yellow atIndex: 2];
*******************
// 10. Exchange two views
// [Self. window exchangeSubviewAtIndex: 0 withSubviewAtIndex: 2];
// Check whether a view is a child view or itself
BOOL is = [red isDescendantOfView: self. window];
NSLog (@ "% d", is );
// The upper left corner of the yellow view is the origin
UIView * green = [[UIView alloc] initWithFrame: CGRectMake (10, 10,100,100)];
Green. backgroundColor = [UIColor greenColor];
[Yellow addSubview: green];
// Place the black view as a child view in the yellow parent View
UIView * black = [[UIView alloc] initWithFrame: CGRectMake (20, 20,100,100)];
Black. backgroundColor = [UIColor blackColor];
[Yellow addSubview: black];
// 11. Crop parts beyond the parent View
Yellow. clipsToBounds = YES;
NSLog (@ "% ld", [self. window subviews]. count );
// 12. Hide A View
// Black. hidden = YES;
// If the parent view is hidden, its child view will also be hidden.
// Yellow. hidden = YES;
// 13. Transparency: if the parent view is set to transparency, all child views on the parent view will also be set to transparency.
// Yellow. alpha = 0.6;
// You can set the transparency of the parent view in the following ways. The child view is not affected.
Yellow. backgroundColor = [[UIColor yellowColor] colorWithAlphaComponent: 0.5];
// 14. User interaction settings
// YES user interaction (you can operate on this UI control)
// NO user interaction is disabled (the user cannot operate this UI control)
/*
UIView is enabled by default.
UIButton is enabled by default for user interaction
UIImageView disabled by default
UILabel disabled by default
*/
// Access the window screen first
// Access self. view (root Controller) again -- actually UIView
// Access the subview myImageView in self. view.
// Finally, access the subview myUIView nested in the subview myImageView.
// If one of the links disables user interaction, the following sub-views cannot be accessed.
Window. userInteractionEnabled = YES;
/*
[Note]
️ User interaction is transmitted layer by layer. If a view of user interaction is disabled, the transmission will not continue.
The parent sub-view should not exceed the boundary of the parent view. Otherwise, it will be invalid to terminate the transmission of user interaction (even if you have already opened user interaction in the parent view)
*/
// 15. Destroy a view (removeFromSuperview)
// Remove a widget from its parent View
// [Note] the removed sub-views with followers will also be removed.
[Yellow removeFromSuperview];