Приостановка проблемы запроса GCD

Я решил свою проблему.

Особенности этого крошечного фрагмента кода:

  • width - динамический
  • , он анимирован
  • для будущих функций намного больше настраивается
    class FirstViewController: UIViewController {
    
    let rectShape = CAShapeLayer()
    let indicatorHeight: CGFloat = 5
    var indicatorWidth: CGFloat!
    let indicatorBottomMargin: CGFloat = 2
    let indicatorLeftMargin: CGFloat = 2
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        // setup tabbar indicator
        rectShape.fillColor = UIColor.redColor().CGColor
        indicatorWidth = view.bounds.maxX / 2 // count of items
        self.tabBarController!.view.layer.addSublayer(rectShape)
        self.tabBarController?.delegate = self
    
        // initial position
        updateTabbarIndicatorBySelectedTabIndex(0)
    }
    
    func updateTabbarIndicatorBySelectedTabIndex(index: Int) -> Void
    {
        let updatedBounds = CGRect( x: CGFloat(index) * (indicatorWidth + indicatorLeftMargin),
                                    y: view.bounds.maxY - indicatorHeight,
                                    width: indicatorWidth - indicatorLeftMargin,
                                    height: indicatorHeight)
    
        let path = CGPathCreateMutable()
        CGPathAddRect(path, nil, updatedBounds)
        rectShape.path = path
    }
    }
    
    extension FirstViewController: UITabBarControllerDelegate {
    
    func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) {
        updateTabbarIndicatorBySelectedTabIndex(tabBarController.selectedIndex)
    }
    }
    
30
задан Kostas.N 12 September 2011 в 13:11
поделиться