So I have the task of learning swift on the fly to make a very basic App. I need to add some "eye candy" so things need some animation, Can anyone help with a time constraint on learning and point me in a direction.
I would like to make the below code when inserting a image add a animation, any will do I just need to see how IOS is expecting me to add this in swift.
import UIKit
class TESTView: UIView {
override func drawRect(rect: CGRect) {
/*
* Set the background image for the App
*/
//Get the graphics context
let context = UIGraphicsGetCurrentContext()
//Get the size of the screen
let entireScreen = UIScreen.mainScreen().bounds
//Set the background image
let backgroundImage = UIImage(named: "brush-strokes.jpg")
//Fill screen with image
backgroundImage?.drawInRect(entireScreen)
/*
* Set the icons for the menu
*/
//Amount of menu items
let menuIcons = 6
//Get the icons in use
let iconOne = UIImage(named: "UnRarX.png")
//smaller size
let newSize = CGSize(width: 50, height: 50)
//Start image editing context to reduce size
UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0)
//Scale icon
iconOne?.drawInRect(CGRectMake(0, 0, newSize.width, newSize.height))
//Get scaled icon
let imageResized = UIGraphicsGetImageFromCurrentImageContext()
//End image editing context
UIGraphicsEndImageContext()
/*
* Lets try place the menu items in a circle
*/
//TODO:Use 10% off all the edges of the screen size
let radius = 100.0
// add .0 to set as double for later
let step = (2 * M_PI) / Double(menuIcons)
// Divide by the number of icons
var angle = 0.0 // Starting angle
//Set 0 point for later
var iconOnePos = CGPoint.zeroPoint
//Loop icons No.
for var i = 1; i <= menuIcons; ++i{
//Calc the current X & Y vals using some maths
var x = (entireScreen.width - 25) / 2 + CGFloat(radius * cos(angle)) // take off 25 for half the icon size
var y = entireScreen.height / 2 + CGFloat(radius * sin(angle))
//Create new point for the icon
iconOnePos = CGPointMake(x, y)
//Draw the image we resized
imageResized?.drawAtPoint(iconOnePos)
//Move the angle for the next calculation
angle += step;
}
}
}