Thursday, June 25, 2015

hide/show with animation in Swift

For hiding the dock like view and show again

 func hide(sender: AnyObject)
 {
     let frame = hideshowView?.frame
     let height = frame?.size.height
     let offsetY = height!
        
     //hide after 10 seconds delay
     if frame != nil {
     UIView.animateWithDuration(0.5, delay: 10.0, options: UIViewAnimationOptions.CurveEaseIn, animations: { [weak self] () -> Void in
                
                if let weakSelf = self
                {
                    weakSelf.segmentedControl?.frame = CGRectOffset(frame!, 0, offsetY)
                    weakSelf.openBottomBarButton.hidden = false
                }
            }) { (Bool v) -> Void in
            }
      }
 }
    
 func show(sender: AnyObject)
 {
        let frame =  hideshowView?.frame
        let height = frame?.size.height
        let offsetY = -height!
        
        //show without delay
        UIView.animateWithDuration(0.5)
        {
            hideshowView?.frame = CGRectOffset(frame!, 0, offsetY)
        
        }
}

No comments:

Post a Comment