PaulMrG
PaulMrG

Reputation: 1822

[UIView setNeedsDisplay]: is there an easy way to know when drawRect is complete?

I have a UIView that I import to display bezier paths with setNeedsDisplay from the super class.

I need to call another method in the super class once the UIView has finished updating. I call the method after setNeedsDisplay however the method is called before UIView has completed redrawing.

As a quick-fix I created an NSTimer with 0.3 seconds before calling the method. That works but could be unreliable. I could also post a notification from the UIView back to the super class but that just seems not right.

I've checked the documentation but can't find anything about a completion notification. Is there any built-in function for this?

Upvotes: 2

Views: 1366

Answers (2)

Philip J. Fry
Philip J. Fry

Reputation: 1165

You can declare a new method

- (void)setNeedsDisplayCompletion:(MYCompletion)completion;

but before that declare typedef

typedef void((^MYCompletion)());

then implement it

- (void)setNeedsDisplayCompletion:(MyCompletion)completion {
    self._completion = [completion copy];
    [self setNeedsDisplay];
}

then use completion block in drawRect

[super drawRect:rect];
if (self._completion) {
    self._completion();
}

P.S. _completion is a property

@property (nonatomic, strong) MyCompletion _completion;

Now you can use your new method

[self._uiTextView setNeedsDisplayCompletion:^{
    [self setNeedsLayout];
}];

Upvotes: 2

Kepler
Kepler

Reputation: 705

Sorry, if I my answer is some incorrect (my english is not so good). Try to declare your super view's method who's reloading uiview (with bizier paths) and change code, when you post notification on code, when you will call that method. Or just try to

[superView performSelectpr:@selector(reloadSubview)];

Upvotes: 0

Related Questions