Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3662596
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:26:03+00:00 2026-05-19T01:26:03+00:00

I have an iPad app that has draggable UIViews contained in a larger parent

  • 0

I have an iPad app that has draggable UIViews contained in a larger parent UIView (which i’ll call the main view). One of the features of the app is the ability to drag between two views to connect them. When dragging i render a line in a CALayer that is rooted on the view that you started dragging on and ends on the user’s finger. If the user ends the drag on top of another view they become attached.

When views are attached there is a line permanently drawn between them.

So in the current implementation there are two CALayers which are sublayers of the main view. One is the linkLayer, which renders the existing links between views. the other is the linkLineLayer which renders the line the user is currently drawing w/ a drag action.

When dragging occurs and an new drag event comes in, i call [linkLineLayer setNeedsDisplay].
similarly, when a user is dragging a view around i call [linkLayer setNeedsDisplay].

the performance is terrible on the actual device, so im guessing that this isn’t the way to go. What alternatives are there to draw lines between views (or points in a view) such that i can update them frequently when dragging a view or dragging a line between views without wrecking the framerate and hammering the device cpu?

Update
So last night i went in and made two fixes that made a huge difference:
1.) all link lines are their own layer. as a view is being dragged around i refresh only the link lines associated w/ that specific view.
2.) updated the “dragging line” to be a layer that whose size is limited to the size of the line being rendered. i adjust the layer bounds as the user’s finger is moving.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:26:04+00:00Added an answer on May 19, 2026 at 1:26 am

    Have you tried rendering the lines as CAShapeLayers? Instead of drawing the line yourself ans calling setNeedsDisplay all of the time, you can just set the path attribute of the CAShapeLayer and let it do the rest.

    Core Animation handles CAShapeLayers differently, and it can optimize the drawing of the path. If you just draw a path yourself in drawLayer:inContext: (or an equivalent) Core Animation has to treat the entire layer as an image because it has no idea what you’ve drawn. If you use a CAShapeLayer, Core Animation knows the path that you want to draw in advance, and it can optimize its rendering accordingly. You also don’t have to worry about the size and position of the shape layer because the layer is just the path.

    Also, an extra pointer, if you want to draw an open path (line) with no fill, you have to set the shape layer’s fillColor property to nil. If you don’t, it will automatically close the path and fill with a default color.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Building an iPad app. I have a button on my main view that I
I have created an iPad app that has 10 view controllers that swipe left
I have an iPad app that has an MKMapView embedded in a UINavigationController which
I am working on an iPad app that has a main view (In this
I have an iPad app that has a UITableViewController that implements the NSFetchedResultsControllerDelegate .
I have a universal iOS app with a custom view that has three buttons,
I have an iPad app that receives data using UDP sockets. And it has
I have a split view controller in my Ipad app, in which the detail
I have an iPad app that has 4 buttons on the left side that
I have an ios app that has a target of both iphone and ipad.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.