SHARE
TWEET

Untitled

a guest Jul 23rd, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var corX = 0
  2. var corY = 0
  3.  
  4. var runter: UIButton = UIButton.buttonWithType(UIButtonType.System) as UIButton
  5.  
  6. var image = UIImage(named: "panzerBlau.jpg");
  7. var panzer = UIImageView(frame: CGRectMake(corX, corY, 30, 40));  //
  8.  
  9. override func viewDidLoad() {
  10.     super.viewDidLoad()
  11.  
  12.     panzer.image = image;    //
  13.     self.view.addSubview(panzer);    //
  14.  
  15.     runter.frame = CGRectMake(100, 30, 10 , 10)
  16.     runter.backgroundColor = UIColor.redColor()
  17.     view.addSubview(runter)
  18.     runter.addTarget(self, action: "fahren", forControlEvents:UIControlEvents.TouchUpInside)
  19. }
  20.      
  21. func fahren(){
  22.     corY += 1
  23.     panzer.frame = CGRectMake(corX, corY, 30, 40) //
  24.     self.view.addSubview(panzer);
  25. }
  26.      
  27. import UIKit
  28.  
  29. class ViewController: UIViewController {
  30.  
  31.     var corX = 0
  32.     var corY = 0
  33.     var runter: UIButton = UIButton.buttonWithType(UIButtonType.System) as UIButton
  34.     var image = UIImage(named: "panzerBlau.jpg");
  35.     var panzer = UIImageView(frame: CGRectMake(corX, corY, 30, 40));
  36.  
  37.     override func viewDidLoad() {
  38.         super.viewDidLoad()
  39.             panzer.image = image;
  40.             self.view.addSubview(panzer);
  41.  
  42.         runter.frame = CGRectMake(100, 30, 10 , 10)
  43.         runter.backgroundColor = UIColor.redColor()
  44.         view.addSubview(runter)
  45.         runter.addTarget(self, action: "fahren", forControlEvents:UIControlEvents.TouchUpInside)
  46.     }
  47.  
  48.     func fahren(){
  49.         corY += 100
  50.         panzer.frame = CGRectMake(corX, corY, 30, 40)
  51.         self.view.addSubview(panzer);
  52.     }
  53. }
  54.      
  55. var corX = 0
  56. var corY = 0
  57. var panzer = UIImageView(frame: CGRectMake(corX, corY, 30, 40))
  58.      
  59. class ViewController: UIViewController {
  60.     var corX : CGFloat = 0
  61.     var corY : CGFloat = 0
  62.     lazy var panzer : UIImageView = UIImageView(frame: CGRectMake(self.corX, self.corY, 30, 40))
  63.     // ...
  64. }
  65.      
  66. let original = "foo"
  67.  
  68. // Good:
  69. lazy var depend: String = self.original
  70.  
  71. // Error:
  72.      var noLazy: String = self.original // Error: Value of type '(NSObject) -> () -> URLData' has no member 'original'
  73. lazy var noType         = self.original // Error: Value of type '(NSObject) -> () -> URLData' has no member 'original'
  74. lazy var noSelf: String = original      // Error: Instance member 'original' cannot be used on type 'YourClass'
  75.      
  76. //
  77. //  ViewController.swift
  78. //
  79. //  Created by Shivank Agarwal on 19/05/18.
  80. //  Copyright © 2018 Shivank Agarwal. All rights reserved.
  81. //
  82.  
  83. import UIKit
  84.  
  85. class ViewController: UIViewController {
  86.  
  87.     var corX = 0
  88.     var corY = 0
  89.     var runter: UIButton = UIButton()
  90.     var image = UIImage(named: "panzerBlau.jpg")
  91.     var panzer = UIImageView()
  92.  
  93.     override func viewDidLoad() {
  94.         super.viewDidLoad()
  95.         panzer.image = image;
  96.         self.view.addSubview(panzer);
  97.         panzer.frame = CGRect(x: CGFloat(corX), y: CGFloat(corY), width: 30, height: 40)
  98.         runter.backgroundColor = UIColor.red
  99.         view.addSubview(runter)
  100.         view.addSubview(panzer)
  101.         runter.addTarget(self, action: Selector(("fahren")), for:UIControlEvents.touchUpInside)
  102.     }
  103.  
  104.     private func fahren(){
  105.         corY += 100
  106.     }
  107.  
  108.     private func updatePanzerFrame(){
  109.         panzer.frame = CGRect(x: CGFloat(corX), y: CGFloat(corY), width: 30, height: 40)
  110.     }
  111. }
  112.  
  113. Note: Do not add panzer imageView every time when user tap only add it on viewDidLoad()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top