2021年4月3日星期六

UIButton on/off stutters when it's target selector performs UIGraphics drawHierarchy code on main thread

I have a UIButton whose target performs some UIGraphicsBeginImageContextWithOptions drawHierarchy steps to create UIImage from a few views.

let toPrint = cell.contentView  UIGraphicsBeginImageContextWithOptions(toPrint.bounds.size, true, 0)  toPrint.drawHierarchy(in: toPrint.bounds, afterScreenUpdates: true)  if let image = UIGraphicsGetImageFromCurrentImageContext() {     images.append(image)  }  UIGraphicsEndImageContext()  

This causes the UIButton's on/off state change animation to stutter.

In iOS when once taps a UIButton, the knob animates from one position to another (off/on -> left to right knob animation). This iOS animation stutters when I perform my drawHierarchy code.

Is there a way to fix this WITHOUT adding a delay?

https://stackoverflow.com/questions/66937673/uibutton-on-off-stutters-when-its-target-selector-performs-uigraphics-drawhiera April 04, 2021 at 11:03AM

没有评论:

发表评论