Saturday, October 1, 2022
HomeiOS Developmentios - Swift Downside in attempting to breed the built-in viewController current...

ios – Swift Downside in attempting to breed the built-in viewController current technique which reveals a view from backside to prime


so I’m attempting to breed the a technique to point out a view from prime to backside simmilar to how UIKit in-built technique of ViewController current does. I’ve no drawback in animating it from backside to prime. The issue is that I’m attempting to make it work simmilar to a sheetPresentationController with detents .medium() and .giant(), that means that the sheet introduced will be dragged towards the highest of the display but in addition to the center of it. Now I’m attempting to do the identical factor with a UIPanGesture. I’ll present the code after which clarify the issue.
That is the tactic of presenting the view animated from backside to prime:
This technique is added within the superview of the view_to_present

    func moveViewToY_selection_place_delegate(y: CGFloat)
      self.view_to_present_from_top.view.tag = 1001;
    UIView.animate(withDuration: 0.2) {
        self.view_to_present_from_top.view.body =  CGRect.init(x: 0.0, y: 0.0,            
         width: self.view.body.width, peak: y)
    } completion: { a in
        //you will note imediately what I'm attempting with the 2 traces of code beneath
        DispatchQueue.world().asyncAfter(deadline: .now() + 0.5) {
            self.view_to_present_from_top.finished_moving = true

        }
    }

Now contained in the view_to_present_from_top class I’ve added a UIPanGestuRerecognizer with this technique as goal

          '''@objc func moveView(_ gestureRecognizer : UIPanGestureRecognizer){
          guard gestureRecognizer.view != nil else {return}
    
    
          let piece = gestureRecognizer.view!
        // Get the adjustments within the X and Y instructions relative to
        // the superview's coordinate area.
    
          let tranlsation_y = gestureRecognizer.location(in: view.superview).y
          let velocity = gestureRecognizer.velocity(in: view.superview)
      
    

           if gestureRecognizer.state == .started {
            print("has started")
            
        //to test to not be already down or already up
            if velocity.y < -200 {
              
            self.is_moving_view = false

                if view_is == .is_down {
                    self.delegate_move.moveViewToY_selection_place(y: 400)
                    view_is = .is_up_medium
                }else {
                    print("now getting into the second")
                    self.delegate_move.moveViewToY_selection_place(y: 120)
                    view_is = .is_down
        //               self.restoreViewBackToNormal()
        
                }
            }
              } else if velocity.y > 200 {
              self.is_moving_view = false
            if view_is == .is_down  {
                print("entered view is down")
                self.delegate_move.moveViewToY_selection_place(y: 400)
                view_is = .is_up_medium
    
            }else if view_is == .is_up_medium  {
                
                self.delegate_move.moveViewToY_selection_place(y: 750)
                view_is = .is_up_large
                print("the view is (view_is)")
    
            }
    
    
           }
          } else if gestureRecognizer.state == .modified {
            
            if self.is_moving_view {
                self.is_moving_view == false
                
                if velocity.y > 200 {
                    self.is_moving_view = false
                    if view_is == .is_down  {
                        print("entered view is down")
                        self.delegate_move.moveViewToY_selection_place(y: 400)
                        view_is = .is_up_medium
            
                    }else if view_is == .is_up_medium  {
                        
                        self.delegate_move.moveViewToY_selection_place(y: 750)
                        view_is = .is_up_large
                        print("the view is (view_is)")
            
                    }
                    
                    
                    
                }else if velocity.y < -200 {
                    self.is_moving_view = false

                        if view_is == .is_up_large {
                            print("entered the primary view")
                            self.delegate_move.moveViewToY_selection_place(y: 400)
                            view_is = .is_up_medium
                        }else {
                            print("now getting into the second")
                            self.delegate_move.moveViewToY_selection_place(y: 120)
                            view_is = .is_down
                //               self.restoreViewBackToNormal()
                
    //                    }
                    }
                    
                    
                    
                    
                }'''
              

The issue with this code is that this:
When a person begins to pull down the view the view can be dragged down from prime to the medium body. Within the case the person nonetheless has the finger on the view and desires to pull it all the way down to a big body, I anticipate that the person will first look forward to the view to be medium and after if it needs the massive one will proceed to the massive one, and the view will scroll to giant. If I dont set the variable finished_moving, then if i do the motion within the started state of the gesture the person wont have the ability to scroll to the massive detent, else if i exploit solely the .modified state the person will immediately scroll to the massive detent.
The issue is that not at all times the code works. What I’m attempting to do is to duplicate the sheetpresentationcontroller technique current with detents medium(),.giant().
Anyone any concepts.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments