How can you check if uiview has appeared on the screen / finished drawing?

I seem to be having problems with the drawrect method. I am drawing a PDF page in a view using CGContextDrawPDFPage and then I want to start the UIView animation in the view frame after it has loaded. However, if I call the animation at the end of the drawrect method, it triggers the jerky animation because the animation is halfway through before the UIView appears on the screen (sometimes after 2 seconds).

I am looking for a way to check if a view has finished drawing. Any ideas or help would be much appreciated?

Here's my code ...

-(void)drawRect:(CGRect)inRect{  

pageRef = [[PDFManager sharedManager] getLargePDFPageRefForPage:pageNumber];
if(pageRef) {
    ctx = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM(ctx, 0.0, [self bounds].size.height);
    CGContextScaleCTM(ctx, 1.0, -1.0);
    CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(pageRef, kCGPDFCropBox, [self bounds], 0, true));
    CGContextSetInterpolationQuality(ctx, kCGInterpolationNone);
    CGContextSetRenderingIntent(ctx, kCGRenderingIntentDefault);

    CGContextDrawPDFPage(ctx, pageRef);    
}

[self moveFrame];

}


-(void)moveFrame{


    [UIView animateWithDuration:0.7 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

        self.frame = CGRectMake(0, 0, 500, 400);


    } completion:^(BOOL finished) {

    }];
}

      

+3


source to share


1 answer


Method AFAIK - drawRect:

Called every time the view "gets dirty" which can be very common. My advice for you would be to write the "moving" code not in the view class, but in the controller class, which is probably better suited for separating concerns (the controller controls the position of the view, and the view controls the drawing itself). The stream will be like this:



  • Initiate the view and add it as a subroutine (in the controller). This will cause the view to draw on its own.
  • Move the actual view to the desired location (in the controller).
0


source







All Articles