Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RotateTextViewVC: UIViewController {
- let tv = UITextView()
- override func viewDidLoad() {
- super.viewDidLoad()
- view.backgroundColor = .systemYellow
- tv.isScrollEnabled = false
- tv.text = "This is some sample text for the text view."
- tv.font = .systemFont(ofSize: 24.0, weight: .regular)
- // add a slider to rotate the text view
- let slider = UISlider()
- slider.addTarget(self, action: #selector(sliderChanged(_:)), for: .valueChanged)
- slider.translatesAutoresizingMaskIntoConstraints = false
- view.addSubview(slider)
- tv.translatesAutoresizingMaskIntoConstraints = false
- view.addSubview(tv)
- let g = view.safeAreaLayoutGuide
- NSLayoutConstraint.activate([
- slider.topAnchor.constraint(equalTo: g.topAnchor, constant: 40.0),
- slider.leadingAnchor.constraint(equalTo: g.leadingAnchor, constant: 20.0),
- slider.trailingAnchor.constraint(equalTo: g.trailingAnchor, constant: -20.0),
- tv.centerXAnchor.constraint(equalTo: view.centerXAnchor),
- tv.centerYAnchor.constraint(equalTo: view.centerYAnchor),
- tv.widthAnchor.constraint(equalToConstant: 200.0),
- ])
- slider.value = 0.5
- }
- @objc func sliderChanged(_ sender: UISlider) {
- let deg: CGFloat = (CGFloat(sender.value) - 0.5) * 720.0
- let radians = deg * .pi / 180.0
- tv.layer.transform = CATransform3DRotate(CATransform3DIdentity, radians, 0, 0, 1)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement