Edit text in a CATextLayer

Discussion in 'Mac Programming' started by misee, Jul 25, 2010.

  1. misee macrumors member

    Jul 4, 2010
    I have a QTMovieView and a CATextLayer (as the QTMovieViews sublayer) to display text (duh). Now, I would like to edit this text when a user clicks an edit button. What would be the best way to get this done?
  2. HiRez macrumors 603


    Jan 6, 2004
    Western US
    Can you use a layer-backed view containing an NSTextField instead of a CATextLayer?
  3. misee thread starter macrumors member

    Jul 4, 2010
    I've thought of that, but CALayers offer me some features I couldn't really get to work with layer backed NSViews. One thing is the positioning. My movie is displayed in a split view. When I collapse this split view and then reopen it, positions are totally messed up when I use NSViews (usually, my view just disappears), but with CALayers and CAConstraintLayoutManager things work perfectly with just 2 lines of code per layer (plus 1 line to set up the layout manager). Maybe there's a way to use CAConstraints with NSViews too, but I couldn't get it to work for me (and didn't find anything on google either except statements that it doesn't exist :(). The other thing is, CATextLayer automatically resizes itself to display the string given to it. I know that can also be done with NSTextView & co., but again, I'd need additional code. Which sucks. Gives me more to debug (and I hate debugging).
    I guess I could try to use an layer backed NSTextView that will be displayed if the text should be edited, and the CATextLayer for the rest of the time.
  4. kainjow Moderator emeritus


    Jun 15, 2000
    One option could be to create an NSTextView inside a borderless/clear/shadowless window and position it directly above the text layer while hiding the text layer and allow the user to edit there, expanding the text view/window as they type.
  5. misee thread starter macrumors member

    Jul 4, 2010
    Yeah, that was my "escape-route". I just thought there might be a more straight-forward way of doing this. It's my first attempt at using Core Animation (which really is much more than just animation).
    Thanks for the replies. (and if anyone has a better solution, please tell me!!!)

Share This Page