На данный момент я создаю некоторые переходы и преобразую через CGAffineTransform
для панорамирования, и я столкнулся с проблемами из-за производительности преобразования под iOS 7
и iPhone 4
.Производительность CGAffineTransforms очень медленная на iOS 7
Я погрузился в Istruments и зарегистрировал материал, и тяжелый подъем выполняется, когда я применяю свои преобразования к виду.
Текущая реализация
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 // really bad performance here
} else {
// reset the transition
}
}
}
Обход прошивкой 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 // really bad performance here
} else {
viewWithTransform.frame = CGRectMake(0, -((containerView!.bounds.height - 40 - 20) * CGFloat(progress)), drawerView!.frame.size.width, drawerView!.frame.size.height); // works like a charm on iOS 7
}
} else {
// reset the transition
}
}
}
Вопрос
Почему производительность так плохо на прошивкой 7 и мой iPhone 4 с CGAffineTransforms
? Потому что он делает то же самое со смещением, а затем с настройкой рамки в обходном пути. Когда я использую UIView.animateWithDuration()
с преобразованием, он выполняет 60 кадров в секунду. Что я могу сделать, чтобы не переписать всю реализацию на моем iOS 7?
ОБНОВЛЕНИЕ 28 июля Обнаружил, что в этом вопросе может участвовать AutoLayout. Вот TimeProfiler Стек из моих текущих вызовов:
Теперь я столкнулся с большой проблемой в моей текущей реализации, потому что я полагаюсь на AutoLayout. Какое самое простое решение для решения этой проблемы на iOS 7?
Is 'viewWithTransform.translate =' что-то пользовательское или предполагается, что оно 'viewWithTransform.transform ='? Вы (намеренно или непреднамеренно) используете автоматическую компоновку? Профилируете ли вы с помощью релизов? –