iOS: How to run a function after Device has Rotated (Swift)

The viewWillTransitionToSize delegate method gets called with a UIViewControllerTransitionCoordinator conforming object. A method that protocol declares is animateAlongsideTransition(_:animation, completion:). You can use that to have code execute after the transition is complete. override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { super.viewWillTransition(to: size, with: coordinator) coordinator.animate(alongsideTransition: nil) { _ in // Your code here } … Read more

Rotate an image in java by the specified angle

Precedence matters… In your second example, you’re apply a rotation AFTER you’ve drawn everything. This is not how graphics works. You need to apply the transformation first, then everything that follows will use that transformation. public class TestRotateImage { public static void main(String[] args) { new TestRotateImage(); } public TestRotateImage() { EventQueue.invokeLater(new Runnable() { @Override … Read more

Creating a UIImage from a rotated UIImageView

OK – at last I seem to have done it. Any comments on the correctness would be useful… needed a translate, a rotate, a scale and an offset from the drawing rect position to make it work. Code is here: CGAffineTransform transform = CGAffineTransformIdentity; transform = CGAffineTransformTranslate(transform, boundingRect.size.width/2, boundingRect.size.height/2); transform = CGAffineTransformRotate(transform, angle); transform = … Read more

C++: Rotating a vector around a certain point

The answer depends on your coordinate system. Computer graphics coordinate system, with (0,0) at Top left If you are using a computer graphics vector implementation where (0,0) is the top left corner and you are rotating around the point (dx, dy), then the rotation calculation, including the translation back into the original coordinate system, would … Read more

UIImageView Gestures (Zoom, Rotate) Question

Hope this can be helpful to you, that’s how I usually implement gesture recognizers: UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotatePiece:)]; [piece addGestureRecognizer:rotationGesture]; [rotationGesture release]; UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scalePiece:)]; [pinchGesture setDelegate:self]; [piece addGestureRecognizer:pinchGesture]; [pinchGesture release]; Rotate method: Reset the gesture recognizer’s rotation to 0 after applying so the next callback is a … Read more