How do i add shadow for UIButton without having lag in Custom Keyboard?

I'm struggling with my Custom Keyboard.

If i add shadow for UIButton object, and turn on AssistiveTouch, it'll get lag during the animation.

The shadow code is here

button.layer.shadowRadius = 3.0f;
button.layer.shadowColor = [UIColor blackColor].CGColor;
button.layer.shadowOffset = CGSizeMake(0.0f, 1.0f);
button.layer.shadowOpacity = 0.5f;
button.layer.masksToBounds = NO;

Any better solution to add shadow to UIButton without having lag with AssistiveTouch?

Anyone can help?

Have you tried to enable rasterization for the layer?


button.layer.shouldRasterize = true
button.layer.rasterizationScale = UIScreen.mainScreen().scale

I've tried, but it still has little bit lag at the beginning.

I've tested many custom keyboard and with these good ones they didn't have this trouble.

any better way to make Button shadow/border without lag ?


I've been facing with this trouble for a year.

Don't know why iOS is still having trouble with their AssistiveTouch while using shadow

Have you tried to use image asset instead of drawing the shadow in the code?

I haven't but i don't think image asset is a right choice for this situation.

Because UIButton is stretchable (in case i switch a keyboard to landscape view).


Now, i'm using UIBezierPath to draw a line at the bottom of UIButton. It brings me a best performance.

But it seems can't create a solid line like above method. And i have to use layoutSubviews to fix shadowPath width for each button between landscape and portrait mode.


This is paintful to do a simple thing with custom keyboard 😟

I'm stuck.

How do i add shadow for UIButton without having lag in Custom Keyboard?
 
 
Q