Implementing iphone's copy/paste controls on a custom view / uiview subclass

前端 未结 1 773
暗喜
暗喜 2020-12-29 14:28

I will admit that there is already a question exactly along these lines here on S.O., but it lacks implementation details, a working answer, and I would like to be more spec

相关标签:
1条回答
  • 2020-12-29 15:08

    I'll say upfront I don't have an aswer, but I did some poking around and found more out. I'm sure you've looked at this already: CopyPasteTile

    That code does work on my simulator and goes like this:

    CGRect drawRect = [self rectFromOrigin:currentSelection inset:TILE_INSET];
    [self setNeedsDisplayInRect:drawRect];
    
    UIMenuController *theMenu = [UIMenuController sharedMenuController];
    [theMenu setTargetRect:drawRect inView:self];
    [theMenu setMenuVisible:YES animated:YES];
    

    There are a few differences here:

    • drawRect is calculated from a giant view tile and tap point calculations
    • setNeedsDisplayInRect is being called
    • self is a large screen sized view, you may need screen coords instead of local coords (you can probably get that from self.superview)

    I'd try making these adjustments to match the example first and see what kind of progress it gets me.

    0 讨论(0)
提交回复
热议问题