この質問は重複していると思いますが、見つかりません =(. (iPhone/iPad)*.xib からロードされる独自の UIView クラスを作成する方法
私は次のことを試していました:
@interface CurtainView : UIView
...
- (id)init {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self = [[[NSBundle mainBundle] loadNibNamed:@"CurtainView_iphone" owner:self options:nil] objectAtIndex:0];
[self setFrame:CGRectMake(0, 0, 320, 460)];
}
else {
self = [[[NSBundle mainBundle] loadNibNamed:@"CurtainView_ipad" owner:self options:nil] objectAtIndex:0];
[self setFrame:CGRectMake(0, 0, 768, 1004)];
}
return self;
}
- (void)drawRect:(CGRect)rect
{
NSLog(@"there should be some animation on view appirance");
}
と ...
CurtainView* curtain = [[CurtainView alloc] init];
NSLog(@"before");
[self.view addSubview:curtain];
[curtain drawRect:CGRectMake(0, 0, 320, 460)];
しかし、この場合、期待した結果が得られず、drawRect が呼び出されません。ユニバーサル アプリ用のカスタム ビューを簡単に作成できる方法があることを願っています。