मेरे पास एक दृश्य में एम्बेडेड बटन है, जो UIBarButtonItem के अंदर है। मैं जो हासिल करना चाहता हूं वह एनीमेशन बनाना है, जो मेरे बटन को कुछ निश्चित मात्रा से दाईं ओर ले जाता है जब मैं बाएं से स्लाइडिंग मेनू खोल रहा हूं और जब मैं इसे बंद कर रहा हूं तो वापस चला जाता है।नेविगेशन बार पर UIView एनीमेशन कभी-कभी गलत काम करता है
मैं इसे बनाने के लिए इस समारोह का उपयोग कर रहा:
static func createMenuButton(controller:UIViewController) -> UIBarButtonItem {
let target = controller.navigationController!.parentViewController!
let menuImage = UIImage(named: "menu.png")!.imageWithRenderingMode(.AlwaysTemplate)
let menuButton = UIButton(frame: CGRectMake(0, 0, 22, 22))
menuButton.tintColor = UIColor.blackColor()
menuButton.setBackgroundImage(menuImage, forState: .Normal)
menuButton.addTarget(target, action: Selector("toggleMenuClicked:"), forControlEvents:.TouchUpInside)
let menuButtonContainer = UIView(frame: menuButton.frame)
menuButtonContainer.addSubview(menuButton)
let menuButtonItem = UIBarButtonItem(customView: menuButtonContainer)
return menuButtonItem
}
मैं भी घुमाना चाहते हैं, लेकिन मैं एक ही समय में 2 गुणों को बदलने के साथ कुछ मुद्दों मिल गया है।
कंटेनर अनुवाद (CGAffine द्वारा अनुवाद ठीक से काम नहीं किया था):
UIView.animateWithDuration(0.3, animations: {
menuContainerView.frame = CGRectOffset(menuContainerView.frame, 183, 0.0)
}, completion: nil)
तो मैं 2 अलग एनिमेशन (यह, उद्घाटन के लिए है उन्हें बंद करने से ही है के लिए लेकिन विपरीत दिशा में) बनाने का फैसला किया गया है
अंदर घुमाएं बटन:
UIView.animateWithDuration(0.3, animations: {
menuButton.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
}, completion: nil)
यह काम करता है - 90% मामलों में। लेकिन कभी-कभी - बंद होने पर - स्क्रीन के बाहर बटन टेलीपोर्ट और वहां से अंत बिंदु की ओर बढ़ता है।
एक ही समय में मैं भी स्क्रीन (ठीक विपरीत मूल्यों को बंद करने के लिए एक ही) के बाहर से मेनू दृश्य नियंत्रक चलती हूँ:
UIView.animateWithDuration(0.3, animations: {
self.leftViewController!.view.frame = CGRect(x: 0, y: self.view.frame.origin.y, width: 183, height: self.view.frame.height)
}, completion: { (Bool) -> Void in
self.menuShown = true
})
मैं भी रंग नेविगेशन पट्टी पर रंग साफ करने के लिए बदल रहा हूँ जब इसे खोला जाता है और इसे खोले जाने पर डिफ़ॉल्ट रंग में वापस किया जाता है।
जब यह टूट जाता है तो यह बहुत अच्छा नहीं लग रहा है। क्या कारण हो सकता है? मेरे द्वारा यह कैसे किया जा सकता है?
बस एक नोट: मैं पहले से ही नींद का उपयोग कर रहा हूं, लेकिन यह हमेशा वैसे भी काम नहीं करता है। मुझे कुछ साफ समाधान की आवश्यकता है :) – Makalele