Don_Mag icon

Untitled

Don_Mag | PRO | 04/17/23 11:56:54 AM UTC | 0 ⭐ | 7807 👁️ | Never ⏰ | []
Swift |

910 B

|

None

|

0 👍

/

0 👎

//
 
class Toast: UIView {
    
}
class ToastTestVC: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .systemYellow
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        showToast("")
    }
    
    var y: CGFloat = 20.0
    func computeToastFrame() -> CGRect {
        // increment y every time this is called
        //  until we get near the bottom, then start
        //  back at the top
        y += 60.0
        if y > view.frame.height - 100.0 {
            y = 80.0
        }
        return .init(x: 100.0, y: y, width: 200.0, height: 50.0)
    }
 
    func showToast(_ message: String) {
        let frame = computeToastFrame()
        let toast = Toast(frame: frame)
        toast.backgroundColor = .red
        view.addSubview(toast)
        UIView.animate(withDuration: 1, delay: 1, options: .allowUserInteraction) {
            toast.alpha = 0.02
        } completion: { _ in
            toast.removeFromSuperview()
        }
    }
 
}
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎