Advertisement
stronk_8s

EXTERNAL_THEORY_CODE

Apr 16th, 2025 (edited)
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 3.21 KB | Source Code | 0 0
  1. //Code for MapKitView and Location based call out
  2.  
  3. import UIKit
  4. import MapKit
  5.  
  6. class ViewController: UIViewController {
  7.     @IBOutlet var mapView: MKMapView!
  8.     override func viewDidLoad() {
  9.         super.viewDidLoad()
  10.         // Do any additional setup after loading the view.
  11.         // setup the map's location and zoom factor
  12.         let lattitude = 21.1702
  13.         let longitude = 72.8311
  14.         var mapRegion:MKCoordinateRegion = MKCoordinateRegion();
  15.         mapRegion.center.latitude = lattitude;
  16.         mapRegion.center.longitude = longitude;
  17.         mapRegion.span.latitudeDelta = 0.5;
  18.         mapRegion.span.longitudeDelta = 0.5;
  19.         mapView.setRegion(mapRegion, animated: true)
  20.         //For creating pin point (CallOut)
  21.         let ant = MKPointAnnotation()
  22.         ant.title="Where am I?...."
  23.         ant.subtitle="I am at VNSGU...."
  24.         ant.coordinate = CLLocationCoordinate2D(latitude: lattitude, longitude: longitude)
  25.         mapView.addAnnotation(ant)
  26.     }
  27. }
  28.  
  29.  
  30. //Code for Auto layout Constraint Animation
  31.  
  32. import UIKit
  33. class ViewController: UIViewController {
  34.     @IBOutlet var imageViewAni: UIImageView!
  35.     var leftAnchor:NSLayoutConstraint?
  36.     var rightAnchor:NSLayoutConstraint?
  37.     //var topAnchor: NSLayoutConstraint?
  38.     //var bottomAnchor: NSLayoutConstraint?
  39.     // var widthAnchor: NSLayoutConstraint?
  40.     //var heightAnchor: NSLayoutConstraint?
  41.     override func viewDidLoad() {
  42.         super.viewDidLoad()
  43.         // Do any additional setup after loading the view.
  44.         imageViewAni.translatesAutoresizingMaskIntoConstraints = false
  45.         imageViewAni.isUserInteractionEnabled = true
  46.         imageViewAni.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(animate)))
  47.         leftAnchor = imageViewAni.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor)
  48.         leftAnchor?.isActive = true
  49.         //topAnchor = imageViewAni.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor)
  50.         //topAnchor?.isActive = true
  51.         rightAnchor = imageViewAni.rightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.rightAnchor)
  52.         //bottomAnchor = imageViewAni.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
  53.         //steveJobsImageView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
  54.         /*widthAnchor = imageViewAni.widthAnchor.constraint(equalToConstant: 100)
  55.         widthAnchor?.isActive = true
  56.         heightAnchor = imageViewAni.heightAnchor.constraint(equalToConstant: 100)
  57.         heightAnchor?.isActive = true*/
  58.     }
  59.     @objc func animate(){
  60.         print("Image is tapped")
  61.         //animation code
  62.         //topAnchor?.isActive = false
  63.         leftAnchor?.isActive = false
  64.         rightAnchor?.isActive = true
  65.         /*bottomAnchor?.isActive = true
  66.          rightAnchor?.constant = -16
  67.          widthAnchor?.constant = 900
  68.          heightAnchor?.constant = 200*/
  69.         UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping:1, initialSpringVelocity: 1,options: .curveEaseOut,animations: {
  70.             self.view.layoutIfNeeded()
  71.             //self.imageViewAni?.frame = CGRect(x:200,y:0,width: 50,height: 50)
  72.         },completion: nil)
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement