SHARE
TWEET

Untitled

a guest Jun 26th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @objc func heartFlurry()
  2. {
  3.     let heartImage = UIImage(named: "heartWhite")
  4.     let heartImageView = UIImageView(image: heartImage)
  5.     let screenSize = UIScreen.main.bounds
  6.     let heartWidth = Int(heartImage!.size.width)
  7.     let heartHeight = Int(heartImage!.size.height)
  8.     let randomX = arc4random_uniform(UInt32(screenSize.width))
  9.     heartImageView.frame = CGRect(x: Int(randomX) - Int(Double(heartWidth) * 0.5), y: Int(screenSize.height) + heartHeight, width: heartWidth, height: heartHeight)
  10.     view.addSubview(heartImageView)
  11.     let randomIntFrom0To4 = Int.random(in: 1..<6)
  12.     print(randomIntFrom0To4)
  13.     self.updateLove()
  14.     self.playSound(sound: "pop_(randomIntFrom0To4)")
  15.     UIView.animate(withDuration: 1.5, animations: {
  16.         heartImageView.center = CGPoint(x: heartImageView.center.x, y: CGFloat(-heartHeight))
  17.     }) { (finished: Bool) in
  18.         heartImageView.removeFromSuperview()
  19.     }
  20. }
  21.      
  22. void heartFlurry() {
  23.  
  24.     Drawable heart = getResources().getDrawable( R.drawable.heart );
  25.     View v = new ImageView(getBaseContext());
  26.     ImageView imageView;
  27.     imageView = new ImageView(v.getContext());
  28.     imageView.setImageDrawable(heart);
  29.  
  30.     Integer heartWidth = heart.getIntrinsicWidth();
  31.     Integer heartHeight = heart.getIntrinsicHeight();
  32.  
  33.     Display display = getWindowManager().getDefaultDisplay();
  34.     Point size = new Point();
  35.     display.getSize(size);
  36.     int width = size.x;
  37.     int height = size.y;
  38.     Log.e("Width", "" + width);
  39.     Log.e("height", "" + height);
  40.  
  41.     final int randomX = new Random().nextInt(size.x);
  42.     Log.e("randomX", "" + randomX);
  43.  
  44.     // RelativeLayout. though you can use xml RelativeLayout here too by `findViewById()`
  45.     final RelativeLayout relativeLayout = new RelativeLayout(this);
  46.  
  47.     // Setting layout params to our RelativeLayout
  48.     RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(size.x, size.y);
  49.  
  50.     // Setting position of our ImageView
  51.     layoutParams.leftMargin = randomX;
  52.     layoutParams.topMargin = 500;
  53.  
  54.     // Finally Adding the imageView to RelativeLayout and its position
  55.     relativeLayout.addView(imageView, layoutParams);
  56.  
  57.     ObjectAnimator animationY = ObjectAnimator.ofFloat(imageView, "translationY", -size.y);
  58.     animationY.setDuration(500);
  59.     animationY.start();
  60.  
  61.     new CountDownTimer(500, 1000) {
  62.         public void onTick(long millisUntilFinished) {
  63.         }
  64.  
  65.         public void onFinish() {
  66.            relativeLayout.removeAllViews();
  67.  
  68.         }
  69.     }.start();
  70.  
  71. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top