objective c - CGAffineTransforms performance is really slow on iOS 7 -


at moment i'm creating transitions , transform via cgaffinetransform panning view , i'm running in troubles because of transform performance under ios 7 , iphone 4.

i dived in istruments , logged stuff , heavy lifting done when i'm applying transforms view.

current implementation

func handlepan(recognizer : uipangesturerecognizer) {          let drawerlocation = recognizer.locationinview(drawerview!)         let locationinview = recognizer.locationinview(containerview!)         let progressmax = containerview!.frame.height - 40 - 20          if(recognizer.state == .changed) {              let offsetdrag = dragstartposition.y - locationinview.y             let progress = float(offsetdrag / progressmax)              if(offsetdrag >= 0) {                  let positiontransform = cgaffinetransformmaketranslation(0, -((containerview!.bounds.height - 40 - 20) * cgfloat(normalizedprogress)))                 viewwithtransform.transform = positiontransform // bad performance here             } else {                 // reset transition             }          } } 

workaround ios 7

func handlepan(recognizer : uipangesturerecognizer) {          let drawerlocation = recognizer.locationinview(drawerview!)         let locationinview = recognizer.locationinview(containerview!)         let progressmax = containerview!.frame.height - 40 - 20          if(recognizer.state == .changed) {              let offsetdrag = dragstartposition.y - locationinview.y             let progress = float(offsetdrag / progressmax)              if(offsetdrag >= 0) {                 if uidevice.currentdevice().systemmajorversion() > 7 {                     let positiontransform = cgaffinetransformmaketranslation(0, -((containerview!.bounds.height - 40 - 20) * cgfloat(progress)))                     viewwithtransform.transform = positiontransform // bad performance here                 } else {                     viewwithtransform.frame = cgrectmake(0, -((containerview!.bounds.height - 40 - 20) * cgfloat(progress)), drawerview!.frame.size.width, drawerview!.frame.size.height); // works charm on ios 7                 }              } else {                 // reset transition             }          } } 

question

why performance bad on ios 7 , iphone 4 cgaffinetransforms? because it's doing same thing offset frame setting in workaround. when use uiview.animatewithduration() transform it's performing on 60fps. can not rewrite whole implementation on ios 7 basis?

update 28th july found out autolayout possible involved in issue. here timeprofiler stack current calls:

time profiler

now i'm facing big problem in current implementation, because rely on autolayout. what's easiest solution solve hassle on ios 7?

while right same thing, under hood, not easy - there matrix multiplications going on place. more on can found here.

it strange if doing this, affects performance - guess layout complicated , re-rendering takes lot of time ; had same problem week ago, here helped me:

  • removing autolayout particular view reason helps lot
  • manipulation frame should used when not rotating / scaling view. becomes need when using those.
  • removing shadows , semi-transparent views, if there more of them behind each other, drops fps when transform used

also, can try assign transform in async call , see if helps:

    dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_high, 0), { () -> void in         dispatch_async(dispatch_get_main_queue(), { () -> void in             // transform view         })     }) 

and if want fancy, use pop framework facebook. great want, , allows fancy stuff bounce, springiness etc. here how can use it:

// create spring animation (there more types, if want) let animation = popspringanimation(propertynamed: kpopviewcenter)  // configure animation.autoreverses = false animation.removedoncompletion = true animation.fromvalue = view.center animation.tovalue = finalpositionpoint  // add new animation view - animation key can whatever like, serves reference view.pop_addanimation(animation, forkey: "youranimationkey") 

edit: if moving view around, use .center property, not frame. saves need define height / width again , gives clearer idea intentions.


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -