2012-04-28 14 views
0

私はView Controllerから呼び出すuiviewサブクラスを持っています。それはすべてを示していますが、サイズを変更できません。私は、ビューのinitwithframeメソッドにブレークポイントを置くとき、それがそのまま現れるが、ビューコントローラは間違いなくそれを変更している...ここでサイズ変更UIViewが動作しない

は私のビューコントローラのコードです:

- (void)resizeWithTag:(int)tag wasTouched:(BOOL)touched 

    { 
     GameBox *tbox = (GameBox *)[self.view viewWithTag:tag]; 
     CGRect frame = tbox.frame; 
     frame = CGRectMake(0, 0, 300, 300); 
     tbox.frame = frame; 
     [tbox setNeedsDisplay]; 
     NSLog(@"%f", tbox.frame.size.width); 
    } 

、ここでは、 initメソッドと

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     // Initialization code 
     [self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1]]; 
     name = [[UILabel alloc] init]; 
     self.autoresizesSubviews = YES; 
    } 
    return self; 
} 



// Only override drawRect: if you perform custom drawing. 
// An empty implementation adversely affects performance during animation. 
- (void)drawRect:(CGRect)rect 
{ 
    // Drawing code 
    int border = 3; 
    UIImage *image = [UIImage imageNamed:@"Sunflower.jpeg"]; 

    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1); 
    CGContextStrokeRectWithWidth(context, CGRectMake(0, 0, rect.size.width, rect.size.height), border); 
    [self attachImage:image inRect:rect inBorder:border]; 
    [name setFrame:CGRectMake(0 + border/2, rect.size.height-10-border/2, rect.size.width-(border), 10)]; 
    [name setFont:[UIFont fontWithName:@"Helvetica" size:9.0]]; 
    [name setBackgroundColor:[UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.0]]; 

    name.textAlignment = UITextAlignmentCenter; 
    [self addSubview:name]; 
} 

答えて

1

initWithFrame:にブレークポイントを置くのUIViewサブクラスのメソッドを描く探しべき適切な場所ではありません。これは、ビューを作成するときに一度だけ呼び出されます。

後でtbox.frame = someFrameを呼び出して、ビューを取得してフレームプロパティを変更しています。これはsetFrame:を呼び出すのと同じです。

このライン

NSLog(@"%f", tbox.frame.size.width); 

あなたが幅を変更なかったことを示す必要があります。

+0

はい、あります。しかし、幅は画面上で変化しません – michaela

関連する問題