0
在下面的代码中,我的drawRect方法从不会被调用。请注意,HypnosisView是从UIView继承的。这里的一些专家能帮助我吗?非常感谢!DrawRect不会在简单的自定义UIView中调用
- (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
下面是我创建的视图,并将其添加到当前窗口中的代码...
- (BOOL)application:(UIApplication *)application 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;
}
Rob,对不对。 '窗口'是零。真的很感谢你的帮助!我不确定要在界面构建器中设置正确的界限,但是我检查了xib文件,主窗口具有对控制器文件“Hyposister应用程序委托”的引用出口。这是正确的,如果不是如何解决这个问题?非常感谢! // PS:我对这件事很陌生,请原谅我犯了愚蠢的错误:) – trillions
Rob,我做了以下操作来初始化'window',现在代码调用了subView的drawRect:CGRect frame = [[UIScreen mainScreen] applicationFrame]; window = [[UIWindow alloc] initWithFrame:frame]; view = [[HypnosisView alloc] initWithFrame:frame]; – trillions
对不起,我仍然有问题,现在在我的drawRect中,没有任何东西被绘制到模拟器。我已经进入代码,一切都看起来很正常,核心图形上下文不是零,坐标在屏幕内。我有点想法...专家,请帮助我,谢谢! – trillions