iOS layer color change

ios swift uiview

462 просмотра

1 ответ

For my custom UIView I've overriden touchesBegan method. What I told it to do is to change its' layer's background color:

    self.layer.backgroundColor = clr_someCGColor

It acts weird. If I quickly tap the view while in Landscape it does everything perfectly well, but if I do this in Portrait, I have to hold it for some time to see the result, however the touchesEnded method is called right away, if I quickly tap. What could be the reason, causing the delay in Portrait?

Автор: EBDOKUM Источник Размещён: 08.11.2019 11:28

Ответы (1)

1 плюс

Remove the dispatch_async wrapper. All it does is cause a delay (we can't execute on the main thread until, as you rightly say, the tap ends and touchesEnded has come and gone). You are already on the main thread, in touchesBegan, so there is no need for this extra delay.

Even better, use a tap gesture recognizer.

Автор: matt Размещён: 20.08.2016 03:02
Вопросы из категории :