0
내보기에는 9 개의 하위보기가 있습니다. (topLeft, top, topRight, left, center, right, bottomLeft, bottom, bottomRight). 내가 animation
을 CGAffineTransform
으로 센터 서브 뷰에서 수행 할 때.다른보기에 비해 CGAffineTransform
이것은 까다로운 질문입니다. 센터 상단의 하위보기가 다룰 예정입니다. 다른 것들은 보상되지 않을 것입니다. 왜?
내 애니메이션의 모든 하위 뷰를 처리하려면 어떻게해야합니까? (가) 변환을 적용하기 전에
override func viewDidLoad() {
super.viewDidLoad()
let top = UIView()
top.backgroundColor = .red
top.frame = CGRect(x: self.view.frame.width/2, y: self.view.frame.height/2, width: 20, height: 20)
top.layer.masksToBounds = true
view.addSubview(top)
let topLeft = UIView()
topLeft.backgroundColor = .orange
topLeft.frame = CGRect(x: self.view.frame.width/2 - 20, y: self.view.frame.height/2, width: 20, height: 20)
topLeft.layer.masksToBounds = true
view.addSubview(topLeft)
let topRight = UIView()
topRight.backgroundColor = .gray
topRight.frame = CGRect(x: self.view.frame.width/2 + 20, y: self.view.frame.height/2, width: 20, height: 20)
topRight.layer.masksToBounds = true
view.addSubview(topRight)
let center = UIView()
center.backgroundColor = .black
center.frame = CGRect(x: self.view.frame.width/2, y: self.view.frame.height/2 + 20, width: 20, height: 20)
view.addSubview(center)
let left = UIView()
left.backgroundColor = .cyan
left.frame = CGRect(x: self.view.frame.width/2 - 20, y: self.view.frame.height/2 + 20, width: 20, height: 20)
view.addSubview(left)
let right = UIView()
right.backgroundColor = .brown
right.frame = CGRect(x: self.view.frame.width/2 + 20, y: self.view.frame.height/2 + 20 , width: 20, height: 20)
view.addSubview(right)
let bottom = UIView()
bottom.backgroundColor = .yellow
bottom.frame = CGRect(x: self.view.frame.width/2 , y: self.view.frame.height/2 + 20 + 20, width: 20, height: 20)
view.addSubview(bottom)
let bottomLeft = UIView()
bottomLeft.backgroundColor = .magenta
bottomLeft.frame = CGRect(x: self.view.frame.width/2 - 20, y: self.view.frame.height/2 + 20 + 20, width: 20, height: 20)
view.addSubview(bottomLeft)
let bottomRight = UIView()
bottomRight.backgroundColor = .green
bottomRight.frame = CGRect(x: self.view.frame.width/2 + 20, y: self.view.frame.height/2 + 20 + 20, width: 20, height: 20)
view.addSubview(bottomRight)
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleTap)))
}
func handleTap(gesture: UITapGestureRecognizer) {
let location = gesture.location(in: view)
for subview in view.subviews {
if subview.frame.contains(location) {
let scaleUp = CGAffineTransform(scaleX: 3, y: 3)
UIView.animate(withDuration: 0.5, animations: {
subview.transform = scaleUp
}) { (success: Bool) in
//subview.transform = .identity
}
}
}
}
당신은 최고입니다! – WeiJay
@WeiJay 감사합니다! 내 대답을 받아 들일만큼 친절하니? –
예. 게시 후 답변을 수락하는 데 시간 제한이 있습니다. D – WeiJay