NEW: Subscribe to Hacking with Swift+ and accelerate your learning! >>

Help, question by CGPoint

Forums > Swift

Good day.
How solve qquestion with transfer CGPOint in function

import UIKit

class ViewController: UIViewController {

    var archorPoint: CGPoint = CGPoint(x: 0.5, y: 0.5)

    override func viewDidLoad() {

        super.viewDidLoad()

        let box = UIView(frame: CGRect(x: 50, y: 50, width: 160, height: 160))
        box.backgroundColor = .blue
        view.addSubview(box)

       box.convertPoinrs(points: archorPoint) //--- ???

        UIView.animate(withDuration: 4) {

        }
    }

    func convertPoints(points: CGPoint) {
        print(1)
    }

}

   

came up with only such a solution

class ViewController: UIViewController {

    var archorPoint: CGPoint = CGPoint(x: 1, y: 1)

    override func viewDidLoad() {

        super.viewDidLoad()

        let box = UIView(frame: CGRect(x: 50, y: 50, width: 160, height: 160))
        box.backgroundColor = .blue
        view.addSubview(box)
        box.layer.anchorPoint = convertPoint(points: archorPoint)
        UIView.animate(withDuration: 4){

        }
    }

    func convertPoint(points: CGPoint) -> CGPoint {
        let ss = points
        print(points)
        return ss
    }
}

   

Hacking with Swift is sponsored by Paw

SPONSORED Use Paw to build, test and describe web APIs. Paw has a lightning fast native macOS interface to compose requests, collaborate in real-time on API specs, and generate client code for your applications. You can import and export API definitions.

Discover Paw for Mac

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

Not logged in

Log in
 

Link copied to your pasteboard.