ios - Weird squishing when updating UIImageView frame after rotating with CGAffineTransform -
i have 2 buttons , 1 uiimageview in main view. 1 button tries rotate uiimageview 30 degrees, , other updates frame of uiimageview itself.
i wouldn't expect setting frame affect visually, instead seems "squish" image if it's in rotation other default orientation. stumbled upon this, wanted update uiimageview's frame in order change x , y coordinates after rotating.
as result, rotate button seems work fine long never push update frame button. if push second button while view ever rotated, however, squishes image state don't understand, or know how undo.
video of second button "squishing" image: https://streamable.com/ba7zd
video of second button "squishing" while rotation isn't default orientation: https://streamable.com/vo3cd
what's reason happening? this question , this question both seem capture similar scenario, i'm unsure how apply either solution.
in viewcontroller:
@iboutlet weak var dog: uiimageview! @ibaction func breakrotate(_ sender: uibutton) { self.dog.frame = self.dog.frame // squishes if rotated } @ibaction func rotatedog(_ sender: uibutton) { uiview.animate(withduration: 1.5, delay: 0, options: [.allowuserinteraction], animations: { self.dog!.transform = self.dog!.transform.rotated(by: cgfloat(0.523599)) // 30 degrees in radians }) }
image:
the value returned frame
property after applying rotation not rotated frame, minimum bounding rectangle encloses view, can different in size actual frame. (the documentation says frame undefined , should ignored in reality it's returning minimum bounding rect)
when apply transform view should not change frame because can interfere transformation.
if want change position after transformation should change center
property of view:
dog.center = newcenterpoint
finally why seeing unusual effect, when transform automatically takes care of resizing frame new minimum bounding rect without messing size of image, when apply new changed frame view won't know result of transform , try resize image , that's why image getting squished that.
Comments
Post a Comment