June 13 movement of the job block

Source: Internet
Author: User

Tag: Class tar color get width Set

Import UIKit

class Viewcontroller: uiviewcontroller {

var greenview:UIView!

Override func viewdidload () {

Super. Viewdidload ()

Additional setup after loading the view, typically from a nib.

// create four system -type buttons to move the view left, right, up, down, respectively

//Create a button for the system type to move the view left

var leftbutton: UIButton = UIButton. Buttonwithtype (uibuttontype. System) as UIButton

// set button size and position

LeftButton. frame = CGRect(x:y: Max,width: +,height:)

// Set Title

LeftButton. Settitle ("←", forstate: uicontrolstate. Normal)

LeftButton. Settitle (" left ", forstate: uicontrolstate. Highlighted)

// Add Action

LeftButton. AddTarget (Self, Action:"didClicked1:", forControlEvents:uicontrolevents. Touchupinside)

// Display button

Self. View. Addsubview (LeftButton)

//Create a button for the system type to move the view right

var rightbutton: UIButton = UIButton. Buttonwithtype (uibuttontype. System) as UIButton

// set button size and position

Rightbutton. frame = CGRect(x:y: $,width: +,height:)

// Set Title

Rightbutton. Settitle ("→", forstate: uicontrolstate. Normal)

Rightbutton. Settitle (" right ", forstate: uicontrolstate. Highlighted)

// Add Action

Rightbutton. AddTarget (Self, Action:"DIDCLICKED2:", forControlEvents:uicontrolevents. Touchupinside)

// Display button

Self. View. Addsubview (Rightbutton)

//Create a button for the system type to move the view up

var upbutton: UIButton = UIButton. Buttonwithtype (uibuttontype. System) as UIButton

// set button size and position

UpButton. frame = CGRect(x:$, y:max, Width:+, Height:)

// Set Title

UpButton. Settitle ("↑", forstate: uicontrolstate. Normal)

UpButton. Settitle (" up ", forstate: uicontrolstate. Highlighted)

// Add Action

UpButton. AddTarget (Self, Action:"DIDCLICKED3:", forControlEvents:uicontrolevents. Touchupinside)

// Display button

Self. View. Addsubview (UpButton)

//Create a button for the system type to move the view down

var downbutton: UIButton = UIButton. Buttonwithtype (uibuttontype. System) as UIButton

// set button size and position

DownButton. frame = CGRect(x:, y: $, Width: +, height:)

// Set Title

DownButton. Settitle ("↓", forstate: uicontrolstate. Normal)

DownButton. Settitle (" down ", forstate: uicontrolstate. Highlighted)

// Add Action

DownButton. AddTarget (Self, Action:"DIDCLICKED4:", forControlEvents:uicontrolevents. Touchupinside)

// Display button

Self. View. Addsubview (DownButton)

// Create a view

var f1 = cgrect(x:y:, Width: +, Height: +)

Greenview = UIView(FRAME:F1)

// Define the background color of the view as Green

Greenview. backgroundcolor = uicolor. Greencolor ()

// Show View

Self. View. Addsubview (Greenview)

}

// Create method to implement view movement

func didClicked1 (sender: UIButton) {

var c = Greenview. Frame

if C.Origin. x = = 0

{

return

}

Else

{

var newframe = cgrect(x:c.Origin. X - ten, y:c.Origin. y, width:c.size. width, height:c.size. height)

Greenview. Frame = Newframe

}

}

func didClicked2 (sender: UIButton) {

var c = Greenview. Frame

if C.Origin. x = =

{

return

}

Else

{

var newframe = cgrect(x:c.Origin. X + ten, y:c.Origin. y, width:c.size. width, height:c.size. height)

Greenview. Frame = Newframe

}

}

func didClicked3 (sender: UIButton) {

var c = Greenview. Frame

if C.Origin. y = = 0

{

return

}

Else

{

var newframe = cgrect(x:c.Origin. x, Y:c.Origin. y - ten, width:c.size. width, height:c.size. height)

Greenview. Frame = Newframe

}

}

func didClicked4 (sender: UIButton) {

var c = Greenview. Frame

if C.Origin. y = = 380

{

return

}

Else

{

var newframe = cgrect(x:c.Origin. x, Y:c.Origin. y + ten, width:c.size. width, height:c.size. height)

Greenview. Frame = Newframe

}

}

Override func didreceivememorywarning () {

Super. Didreceivememorywarning()

//Dispose of any resources, can be recreated.

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.