× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Get the bounds of a rectangle after rotation

<p>Function in swift to get the bounds of a rectangle after a degree rotation.     </p> <p> </p> <p>    func getBoundingRectAfterRotation(rect: CGRect, angle: Float) -&gt; CGRect {</p> <p>    let newWidth : Float = Float(rect.size.width) * abs(cosf(angle)) + Float(rect.size.height) * fabs(sinf(angle))</p> <p>    </p> <p>    let newHeight : Float = Float(rect.size.height) * fabs(cosf(angle)) + Float(rect.size.width) * fabs(sinf(angle))</p> <p>    </p> <p>    let newX : Float = Float(rect.origin.x) + ((Float(rect.size.width) - newWidth) / 2);</p> <p>    let newY : Float = Float(rect.origin.y) + ((Float(rect.size.height) - newHeight) / 2);</p> <p>    let rotatedRect : CGRect = CGRectMake(CGFloat(newX), CGFloat(newY), CGFloat(newWidth), CGFloat(newHeight))</p> <p>    return rotatedRect</p> <p>    }</p>
comments powered by Disqus