Вопрос

I have custom draggable UITextViews, and latest dragged UITextView has the biggest zPosition(textView.layer.zPosition) to make sure it appears on top of other textViews, but when I drag textViews on top of each other, and then try to move the one appears on top, latest added(to superview) textView's hitTest runs first and application decides that it got hit, even tho I need the one with biggest zPosition(latest moved one)

I tried modifying the hitTest to check if there are other textViews on touch location with bigger zPosition, but hitTest gives location based on textView's bounds(top left corner is x=0 y=0)

So is there a way to change the sequence hit test runs without removing the view and adding it again, or can you think of another way to make sure right view gets hit

example situation

Это было полезно?

Решение

Ok, I fixed hitTest using textView's own frame. Since point from hittest was giving me location based on textView's bounds,

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    //Real location of point in superview
    CGPoint pointInEditingView = CGPointMake(self.frame.origin.x+point.x, self.frame.origin.y+point.y);

then I checked if there are other textViews on touch location with larger zPosition value, and returned nil if there were

Другие советы

Use bringSubviewToFront on your superview with the latest moved UITextView.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top