When i changed the frame of view, and will the frame of layer change with it? Why ?For example .
UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 50)];
[self.view addSubview:testView];
NSLog(@"(%f,%f,%f,%f)", testView.layer.frame.origin.x, testView.layer.frame.origin.y, testView.layer.frame.size.width, testView.layer.frame.size.height);
testView.frame = CGRectMake(200, 200, 100, 100);
NSLog(@"(%f,%f,%f,%f)", testView.layer.frame.origin.x, testView.layer.frame.origin.y, testView.layer.frame.size.width, testView.layer.frame.size.height);
Output:
2018-03-07 22:13:33.251349+0800 ViewLayer[25622:1982995] layer frame:(100.000000,100.000000,100.000000,50.000000)
2018-03-07 22:13:33.251483+0800 ViewLayer[25622:1982995] layer frame:(200.000000,200.000000,100.000000,100.000000)
No, the frame a of Layer does not change with the frame of the view.
Why? Because they are used for different tasks, and layers have their own coordinate space.
I suggest you take a read through the documentation - here's a good place to start: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreAnimation_guide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40004514
If you want a layer's frame to change with the view's frame, you need to subclass that view and override / implement layoutSubviews
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.