Create clickable body diagram with Swift (iOS)

前端 未结 3 888
粉色の甜心
粉色の甜心 2020-12-18 00:36

I\'m trying to recreate something for a iOS app (Swift) which I already made in HTML5 (using map area-coords).

I want to

3条回答
  •  星月不相逢
    2020-12-18 01:09

    There is no built-in mechanism for detecting taps in irregular shapes. The standard UIView tap detection uses frame rectangles. (Likewise with CALayers, as suggested by sketchyTech in his comment above.)

    I would suggest drawing your body regions as bezier paths. You could create a custom subclass of UIView (BodyView) that would manage an array of BodyRegion objects each of which include a bezier path.

    The UIBezierPath class includes a method containsPoint that lets you tell if a point is inside the path. Your BodyView could us that to decide which path object was tapped.

    Bezier paths would handle both drawing your body regions and figuring out which part was tapped.

提交回复
热议问题