Hello!
I am new to this and there will probably exist a short and quick answer to this problem, to give a short overview:
What I want: to increase the size of buttons on touch of the +-sign, then to highlight the correct button if the corresponding button is touched inside.
So far: I have designed a custom class "AddButton.swift" inherited from UIControl, and inside that control I have added a few buttons "AddButtonOption.swift" (also custom class inherited from CALayer), everything works great so far and looks good on the screen.
Problem :The problem strikes when I have resized the buttons, the touch only seem to respond inside the old UIView from before it has been resized (to a bigger size). I guess the problem lays in "touch.locationInView(self))", but after many attempts I have to ask for advice.
Code of interest:
AddButton.swift
override func beginTrackingWithTouch(touch: UITouch, withEvent event: UIEvent?) -> Bool {
...
let getBig = CATransform3DScale(button1Scale,resizeFactor, resizeFactor, 1.0)
...
for tbutton in button{
UIView.animateWithDuration(1.0, delay: 0, usingSpringWithDamping: 0.04, initialSpringVelocity: 0.2, options: .CurveEaseOut, animations: {tbutton.transform=getBig}, completion: nil)
}
...
}AddButton.swift
override func continueTrackingWithTouch(touch: UITouch, withEvent event: UIEvent?) -> Bool {
for buttont in button{
if(buttont.containsPoint(touch.locationInView(self))){
buttont.touchOver()
buttont.setNeedsDisplay()
}else{
buttont.touchDisappear()
buttont.setNeedsDisplay()
}
}
return true;
}AddButtonOption.swift
override func containsPoint(p: CGPoint) -> Bool {
return CGPathContainsPoint(sl.path, nil, p, false)
}