开发者

DrawRect does not get called in a simple customized UIView

开发者 https://www.devze.com 2023-04-07 22:26 出处:网络
In the code below, my drawRect method is never called. Note tht HypnosisView is inherited from UIView. Can some experts here help me out? Thanks a lot!

In the code below, my drawRect method is never called. Note tht HypnosisView is inherited from UIView. Can some experts here help me out? Thanks a lot!

- (void)drawRect:(CGRect)rect
{
// This code is never getting called.... 
    NSLog(@"in drawRect...");

    // Drawing code -- no need to post this since this function is not even getting called
}


@end

Below is the code I created the view and added it to the current window...

- (BOOL)application:(UIApplication *)applicat开发者_JAVA技巧ion didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    CGRect wholeWindow = CGRectMake(0,0,320,460); //[window bounds];
    view = [[HypnosisView alloc] initWithFrame:wholeWindow];
    [view setBackgroundColor:[UIColor clearColor]];
    [window addSubview:view];

    [view setNeedsDisplay];

    [self.window makeKeyAndVisible];
    return YES;
}


The most likely cause is that window is nil. Make sure it's correctly bound in Interface Builder.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号