RainCast
RainCast

Reputation: 4491

iOS swift - how to draw an ellipse with touch event

currently I am trying to port my old windows phone app to iphone. The UI looks like this:

enter image description here

I want to know how to do the following:

  1. Draw a solid ellipse on a specific position, e.g. at position x = 0, y = 0;
  2. The ellipse change its color upon touch;
  3. Touch another position on screen, the ellipse animated to move to the specific position.

I tried several tutorial on how to override drawRect in UIView, but couldn't get it work, can anyone help provide a simple sample?

Thanks a lot!

Edit: Any sample code is highly appreciated. There aren't much swift code on the internet and samples are not easy to find...

Upvotes: 1

Views: 739

Answers (1)

Wim Haanstra
Wim Haanstra

Reputation: 5998

Animating inside a drawRect is never recommended. Why not just put an UIView on the place where you want it and animate the coordinates of that view?

The UIView could be a custom view responding to touch and then triggering the drawRect with a new color.

The parent view where you place these views on can respond to touches and move the ellipse view to the right position.

Upvotes: 1

Related Questions