nrlnishan / ViewPager-Swift

Simple View Pager library for swift using UIPageViewController and Scroll View
MIT License
174 stars 48 forks source link

UI Messed Up on notch devices #65

Open anand-y opened 4 years ago

anand-y commented 4 years ago

I am using version 1.2.1. My issue on devices with notch is that, whenever I minimize(send app to background) and then open it up again the some ui components (i.e. buttons) move below safe area hence become inactive/useless.

I pushing this ViewPagerViewController on from navigationcontroller embedded inside TabbarViewController

correct distorted

My code is as follows

import UIKit
import ViewPager_Swift

class OrderDetailsPagerViewController: BaseViewController {

    var viewPager:ViewPagerController!
    var options:ViewPagerOptions!
    var tabs: [ViewPagerTab]  = [ViewPagerTab(title: NSLocalizedString("order_details", comment: "").uppercased(), image: nil),ViewPagerTab(title: NSLocalizedString("order_details_Item", comment: "").uppercased(), image: nil)]

    override func viewDidLoad() {
        super.viewDidLoad()
        configureViewPager()
    }

    func configureViewPager() {
        self.edgesForExtendedLayout = UIRectEdge.init(rawValue: 0)
        options = ViewPagerOptions(viewPagerWithFrame: self.view.bounds)
        options.tabType = .basic
        options.fitAllTabsInView = true
        options.tabViewImageSize = CGSize(width: 20, height: 20)
        options.tabViewTextFont = UIFont.b2cLatoBold(size: 14)
        options.tabViewPaddingLeft = 10
        options.tabViewPaddingRight = 10
        options.isTabHighlightAvailable = true
        options.tabViewTextDefaultColor = Helper.sharedInstance.hexStringToUIColor(hex: "#ffffff")
        options.tabViewTextHighlightColor = Helper.sharedInstance.hexStringToUIColor(hex: "#ffffff")
        options.tabViewBackgroundDefaultColor = Helper.sharedInstance.hexStringToUIColor(hex: "#017478")
        options.tabViewBackgroundHighlightColor = Helper.sharedInstance.hexStringToUIColor(hex: "#017478")
        options.tabIndicatorViewBackgroundColor = Helper.sharedInstance.hexStringToUIColor(hex: "#ffffff")

        self.navigationController?.navigationBar.barStyle = UIBarStyle.black

        self.navigationController?.navigationBar.barTintColor  = Helper.sharedInstance.hexStringToUIColor(hex: "#017478")
        // self.navigationController?.navigationBar.tintColor  = Helper.sharedInstance.hexStringToUIColor(hex: "#017478")
        self.navigationController?.navigationBar.tintColor = UIColor.white

        viewPager = ViewPagerController()
        viewPager.options = options
        viewPager.dataSource = self
        viewPager.delegate = self

        self.addChildViewController(viewPager)
        self.view.addSubview(viewPager.view)
        viewPager.didMove(toParentViewController: self)

    }
}
extension MyViewController:ViewPagerControllerDataSource
{
    func tabsForPages() -> [ViewPagerTab] {
        return tabs
    }

    func numberOfPages() -> Int {
        return tabs.count
    }

    func viewControllerAtPosition(position: Int) -> UIViewController {
        let vc = UIStoryboard.loadOrderDetailsViewController()
        vc.order = self.order
        vc.pagerIndex = position
        vc.orderDetails = self.orderDetails
        vc.dataSource = self.dataSource
        vc.viewPager = self.viewPager
        return vc
    }

    func startViewPagerAtIndex() -> Int {
        return 0
    }
}

extension OrderDetailsPagerViewController:ViewPagerControllerDelegate
{
    func willMoveToControllerAtIndex(index:Int) {
        print("Moving to page \(index)")
    }

    func didMoveToControllerAtIndex(index: Int) {
        print("Moved to page \(index)")
    }
}

I have tried to change the initialisation frame wrt to safe area but that did not help

let viewBoundsX = self.view.bounds.minX
let viewBoundsY = self.view.bounds.minY
let viewBoundsHeight = self.view.bounds.height - (UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0)
let viewBoundsWidth = self.view.bounds.width - (UIApplication.shared.keyWindow?.safeAreaInsets.left ?? 0) - (UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0)

let safeAreaFrame = CGRect(x: viewBoundsX, y: viewBoundsY, width: viewBoundsWidth, height: viewBoundsHeight)

options = ViewPagerOptions(viewPagerWithFrame: safeAreaFrame)

The view load correctly, but when minimised and opened again produces the following result.

safeAreaDistorted

Please help me with this

codingdoze commented 4 years ago

I'm having kind of similar issue I have a scrollview in which last 2 subviews are getting obscured and cannot scroll all the way

Did you get this resolved?? @anand-y