所以我的任务是快速学习swift来制作一个非常基本的应用程序。 我需要添加一些" eye candy"所以事情需要一些动画,任何人都可以帮助学习时间限制,并指出我的方向。
我想在插入图片时添加动画制作下面的代码,我只需要看看IOS是如何期望我在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;
}
}
}