Victor Choi

  • Home
  • Business
    • Internet
    • Market
    • Stock
  • Parent Category
    • Child Category 1
      • Sub Child Category 1
      • Sub Child Category 2
      • Sub Child Category 3
    • Child Category 2
    • Child Category 3
    • Child Category 4
  • Featured
  • Health
    • Childcare
    • Doctors
  • Home
  • Business
    • Internet
    • Market
    • Stock
  • Downloads
    • Dvd
    • Games
    • Software
      • Office
  • Parent Category
    • Child Category 1
      • Sub Child Category 1
      • Sub Child Category 2
      • Sub Child Category 3
    • Child Category 2
    • Child Category 3
    • Child Category 4
  • Featured
  • Health
    • Childcare
    • Doctors
  • Uncategorized
Showing posts with label CALayer. Show all posts
Showing posts with label CALayer. Show all posts

8/12/2016

The relationship between AnchorPoint and Position in Layer

 3:21 PM     AnchorPoint, CALayer, iOS, Layer, Position, View     No comments   

I felt difficult to understand the relationship between AnchorPoint and Position in Layer. So I found this in stackoverflow. And it helped me a lot to understand it.

Through my testing I got some principle.

  • If a layer’s frame is already defined , the anchorpoint doesn’t affect the position of the layer.

  • If you change an anchorPoint of a layer which already has a frame and a position , the origin of the layer’s frame will be changed by the setting of anchorPoint.

    let view = UIView(frame: CGRectMake(0,0,400,400))
    view.backgroundColor = UIColor.grayColor()
    let label1 = UILabel(frame: CGRectMake(100,100,100,20))
    label1.text = "Label1"
    print("AnchorPoint: \(label1.layer.anchorPoint) , Frame: \(label1.layer.frame)")
    print("Position: \(label1.layer.position)")
    label1.backgroundColor = UIColor.whiteColor()
    view.addSubview(label1)
    view
    
    // AnchorPoint to (1,1) 
    
    label1.layer.anchorPoint = CGPoint(x: 1.0, y: 1.0)
    label1.text = "Label1"
    print("AnchorPoint: \(label1.layer.anchorPoint) , Frame: \(label1.layer.frame)")
    view.addSubview(label1)
    view
    
  • If you set up a layer’s anchorPoint before you set up the frame of the layer, the position of the layer will be affected by setting of the anchorPoint.

    let label2 = UILabel()
    label2.layer.anchorPoint = CGPoint(x: 1.0, y: 1.0)
    label2.frame = CGRect(origin: CGPoint(x: 100,y: 100), size: CGSize(width: 100.0, height: 20.0))
    print("AnchorPoint: \(label2.layer.anchorPoint) , Frame: \(label2.layer.frame)")
    print("Position: \(label2.layer.position)")
    
    let label3 = UILabel()
    label3.layer.anchorPoint = CGPoint(x: 0.0, y: 0.0)
    label3.frame = CGRect(origin: CGPoint(x: 100, y: 100), size: CGSize(width: 100.0, height: 20.0))
    print("AnchorPoint: \(label3.layer.anchorPoint) , Frame: \(label3.layer.frame)")
    print("Position: \(label3.layer.position)")
    
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Older Posts Home

Search This Blog

Popular Posts

  • Git ignore vs Git exclude
  • Keynote Tutorial Character Style , How to use a character style in Keynote
  • If you can't get OAuth Token by SFSafariViewController...?
  • Bitbucket authentication error, Invalid username and password
  • OmniFocus Review Perspective action using Launch Center Pro

Blog Archive

  • ▼  2020 (2)
    • ▼  January (2)
      • Error- helm docker-registry does not have any acti...
      • How to clean up none docker images
  • ►  2019 (21)
    • ►  December (2)
    • ►  November (6)
    • ►  October (5)
    • ►  September (2)
    • ►  August (3)
    • ►  July (2)
    • ►  June (1)
  • ►  2017 (11)
    • ►  December (2)
    • ►  November (2)
    • ►  July (2)
    • ►  May (1)
    • ►  April (1)
    • ►  March (3)
  • ►  2016 (48)
    • ►  December (3)
    • ►  November (2)
    • ►  September (1)
    • ►  August (10)
    • ►  July (5)
    • ►  June (7)
    • ►  May (2)
    • ►  April (18)
Powered by Blogger.

Navigation Menu

  • Home
  • About
  • Documentation
  • Contact

Contact Us

Name

Email *

Message *

Copyright © Victor Choi | Powered by Blogger
Design by Hardeep Asrani | Blogger Theme by NewBloggerThemes.com | Distributed By Gooyaabi Templates