Instructions integration with tab bar and cell in iOS swift

 Problem:

I had integrated Instructions pod in my project.I want to integrate instructions in my project with tab bar with instructions as well as if cell available then show.Otherwise not show with cell instructions.

Solution:

The below code will be used for get the frame for tab bar icons and collectionview header icon focus instructions.

import Instructions

    var coachFrames:[CGRect] = []

    var coachStrArray:[String] = []



    //   # MARK: - viewDidAppear

    override func viewDidAppear(_ animated: Bool) {

            addDemoFrames()

        }


    //   # MARK: - add frames

    func addDemoFrames() {

            DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1), execute: {

                self.coachFrames = []

                self.coachStrArray = []


                if let topController = UIApplication.topViewController() as? TabBarVC {

                    let itemCount = topController.viewControllers.count

                    for i in 0..<itemCount { //tab bar icons

                        var frme = self.getFrames(item: i, frm: topController.frameForTabBarItem(at: i) ?? CGRectZero)

                        if i==0 {

                            frme.origin.y = frme.origin.y-30

                            frme.size.height = frme.size.height+30

                        }

                        self.coachFrames.append(frme)

                        self.coachStrArray.append(self.menuStrings[i])

                    }

                    var menuFrame = self.navBar.frame

                    menuFrame.size = CGSize(width: 50, height: 50)

                    self.coachFrames.append(menuFrame)

                    self.coachStrArray.append(mystring)

                    var searchFrame = self.navBar.frame

                    searchFrame.origin.x = (searchFrame.origin.x+searchFrame.size.width)-50

                    searchFrame.size = CGSize(width: 50, height: 50)

                    self.coachFrames.append(searchFrame)

                    self.coachStrArray.append(searchIconString)


                if let frame1 = self.getHeaderFrameSize(index: 0) {

                    self.coachFrames.append(frame1)

                    self.coachStrArray.append(mycellstring1)

                }

                if self.array2.count>0,let frame2 = self.getHeaderFrameSize(index: 1) {

                    self.coachFrames.append(frame2)

                    self.coachStrArray.append(mycellstring2)

                }

                if self.array3.count>0,let frame3 = self.getHeaderFrameSize(index: 2) {

                    self.coachFrames.append(frame2)

                    self.coachStrArray.append(mycellstring3)

                }

                self.coachFrames.append(self.view.frame)

                self.coachMarksController.start(in: .window(over: self))

                }

            })

           

    }


    func getFrames(item:Int,frm:CGRect) -> CGRect {

        var frames = frm

        let safeAreaInsets = self.view.safeAreaInsets

        let safeAreaHeight = safeAreaInsets.top + safeAreaInsets.bottom - 20

        frames.origin.y = frames.origin.y-safeAreaHeight

        return frames

    }



extension MyVC {

    func getHeaderFrameSize(index:Int) -> CGRect? {

        guard let layout = CollView.collectionViewLayout as? UICollectionViewFlowLayout else {

            return nil

        }

        

        let indexPath = IndexPath(item: 0, section: index)

        let layoutAttributes = layout.layoutAttributesForSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, at: indexPath)

        if var frameNew = layoutAttributes?.frame {

            frameNew.origin.y = frameNew.origin.y+self. CollView.frame.origin.y

            frameNew.origin.x = frameNew.origin.x+self. CollView.frame.origin.x

            frameNew.size = CGSize(width: 50, height: 50)

            return frameNew

        } else {

            return layoutAttributes?.frame

        }

    }

}

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift