[英]When i changed the frame of view, and will the frame of layer change with it?
當我更改視圖框架時,圖層的框架會隨之變化嗎? 為什么?例如。
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);
輸出:
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)
不,Layer的框架a 不會隨視圖的框架而變化。
為什么? 因為它們用於不同的任務,並且圖層具有自己的坐標空間。
我建議您通讀文檔-這里是一個不錯的起點: https : //developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreAnimation_guide/Introduction/Introduction.html#//apple_ref/doc / uid / TP40004514
如果要使圖層的框架隨視圖的框架而變化,則需要對該視圖進行子類化並重寫/實現layoutSubviews
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.