slide menu
Mon Oct 09 2023 07:52:02 GMT+0000 (Coordinated Universal Time)
Saved by @hasnat #ios #swift #menu #slide #slidemenu #slider #slideview
override func viewDidLoad() { super.viewDidLoad() setSwipeGesture() } func setSwipeGesture() { let swipeRightGesture = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe(_:))) if AppDelegate.selectedLanguage == "en" { swipeRightGesture.direction = .right } else { swipeRightGesture.direction = .left } view.addGestureRecognizer(swipeRightGesture) } @objc func handleSwipe(_ gesture: UISwipeGestureRecognizer) { if gesture.direction == .right && isOpen == false && AppDelegate.selectedLanguage == "en" { toggleSideMenu() } else if gesture.direction == .left && isOpen == false && AppDelegate.selectedLanguage == "ar" { toggleSideMenu() } } override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { if isOpen && AppDelegate.selectedLanguage == "en" { if let touch = touches.first { let location = touch.location(in: view) if location.x < 50 { // Adjust the threshold as needed toggleSideMenu() } } else if isOpen && AppDelegate.selectedLanguage == "ar" { if let touch = touches.first { let location = touch.location(in: view) if location.x > view.frame.size.width - 50 { // Adjust the threshold as needed toggleSideMenu() } } } } } func toggleSideMenu() { if AppDelegate.selectedLanguage == "en" { UIView.animate(withDuration: 0.15) { if self.isOpen { self.sideMenuView.frame.origin.x = -self.sideMenuView.frame.size.width self.isOpen = false } else { self.sideMenuView.frame.origin.x = 0 self.isOpen = true } } } else { UIView.animate(withDuration: 0.15) { if self.isOpen { self.sideMenuView.frame.origin.x = self.view.frame.size.width // Slide it to the right side self.isOpen = false } else { self.sideMenuView.frame.origin.x = self.view.frame.size.width - self.sideMenuView.frame.size.width // Slide it to the left side self.isOpen = true } } } } func shareLinkOnSocialMedia(link: URL, viewController: UIViewController) { let activityViewController = UIActivityViewController(activityItems: [link], applicationActivities: nil) activityViewController.popoverPresentationController?.sourceView = viewController.view viewController.present(activityViewController, animated: true, completion: nil) } @IBAction func menuPressed(_ sender: Any) { toggleSideMenu() } @IBAction func backMenuButton1Pressed(_ sender: Any) { toggleSideMenu() }
Comments