ios - UINavigationItem animation -


i trying create custom animation uinavigationitem. have navigation bar 4 items, when scroll down want put search bar in navigation. have animation bottom-top, tried not working.

here stuff tried:

  • setleftbarbuttonitem:animated: (it working, jerky - not fluid @ all. kinda looks gif...
  • uiview with: animation,delay, option, hanlder, every method ui animations ( not working @ all)

i should note have 1 button , search bar in navigation after scroll.

my question - possible change default animation , make own? and, if so, how can achieve that?

i'm not sure understand you're trying exactly, place custom view leftbarbuttonitem , animate want (you'll need implement touch handling in view, though)...

depending on animation need, use uiscrollview custom view , set it's contentoffset depending on contentoffset of views scrollview (creating similar effect twitter app uses when viewing users main page).

i tried first method (custom view animations) , seems work quite nicely:

class itemview : uiview {     var active : bool {         set {             uiview.animatewithduration(1, animations: {                 if newvalue {                     self.backgroundcolor = uicolor.greencolor()                     self.transform = cgaffinetransformmakerotation(3.1415/2)                 } else {                     self.backgroundcolor = uicolor.redcolor()                     self.transform = cgaffinetransformmakerotation(-3.1415/2)                 }             })         }         {             if let color = backgroundcolor {                 return color.isequal(uicolor.greencolor())             }             return false         }     } } 

i used (i'm changing active state simple event handler, linked rightbarbuttonitem, can use here, including scrollviewdidscroll:):

let item = itemview(frame: cgrectmake(0, 0, 30, 20))  override func viewdidload() {     super.viewdidload()      item.active = false      self.navigationitem.setleftbarbuttonitem(uibarbuttonitem(customview: item), animated: false) }  @ibaction func itemclicked(sender: uibarbuttonitem) {     item.active = !item.active } 

Comments