
- iOS Tutorial
- iOS - Home
- iOS - Getting Started
- iOS - Environment Setup
- iOS - Objective-C Basics
- iOS - First iPhone Application
- iOS - Actions and Outlets
- iOS - Delegates
- iOS - UI Elements
- iOS - Accelerometer
- iOS - Universal Applications
- iOS - Camera Management
- iOS - Location Handling
- iOS - SQLite Database
- iOS - Sending Email
- iOS - Audio & Video
- iOS - File Handling
- iOS - Accessing Maps
- iOS - In-App Purchase
- iOS - iAd Integration
- iOS - GameKit
- iOS - Storyboards
- iOS - Auto Layouts
- iOS - Twitter & Facebook
- iOS - Memory Management
- iOS - Application Debugging
- iOS Useful Resources
- iOS - Quick Guide
- iOS - Useful Resources
- iOS - Discussion
How to rotate an image in imageview by an angle on iOS App using Swift?
Images are everywhere almost in all application, you might have come across many applications like gaming applications where you see images getting rotated.
So, In this post, we will be seeing how to rotate the image in an image view by an angle in an iOS application.
So, Let’s get started,
Step 1 − Open Xcode→SingleViewApplication→name it RotateImage.
Step 2 − Open Main.storyboard, add UIImageView and add 2 buttons as shown below name them ROTATE BY 90 DEGREES AND ROTATE BY 45 DEGREES. Add some sample images to UIImage View.
Step 3 − Create @IBAction for both buttons and name them as rotate45button and rotate90button
@IBAction func rotate90button(_ sender: Any) { } @IBAction func rotate45button(_ sender: Any) { }
Step 4 − Create @IBOutlet for UIImageView and name it imageView
@IBOutlet var imageView: UIImageView!
Step 5 − Now add below line in our rotate methods,
imageView.transform = imageView.transform.rotated(by: CGFloat(Double.pi / “value by which you want to rotate”))
Your code should look like,
@IBAction func rotate90button(_ sender: Any) { imageView.transform = imageView.transform.rotated(by: CGFloat(Double.pi / 2)) //90 degree } @IBAction func rotate45button(_ sender: Any) { imageView.transform = imageView.transform.rotated(by: CGFloat(Double.pi / 4)) // 45 degree }
Now run the application to see the result.
You can divide any number to pi based on the degree in which you want to rotate.
- Related Articles
- How to rotate an image in imageview by an angle on Android using Kotlin?
- How to rotate an Image in ImageView by an angle on Android?
- How to load and display an image on iOS App using Swift?
- How to display an image with rounded corners on iOS App using Swift?
- How to make an HTTP request on iOS App using Swift?
- PyTorch – How to rotate an image by an angle?
- How to make an HTTP POST request on iOS App using Swift?
- How do I load an image by URL on iOS device using Swift?
- How to load and display an image in ImageView on Android App?
- How to create a WebView in an iOS App using Swift?
- How to Rotate image in image view by an angle in Android?
- How to make an ImageView with rounded corners on Android App using Kotlin?
- How to create a Custom Dialog box on iOS App using Swift?
- How to make an ImageView with rounded corners on Android App?
- How to rotate an image with a given angle using imagerotate() function in PHP?
