2011-12-05 34 views
5

Tôi đã tìm thấy rất nhiều thông tin về tự động hóa nhưng không ai có thể giải quyết được vấn đề của tôi. Tôi có một ViewController (RAViewController) Đấng kêu gọi một cái nhìn trong phương pháp loadView của nó như sau:Tự động hóa mặt nạ hoạt động như thế nào?

- (void)loadView 
{ 
    // Set Navigation Bar Title 
    self.navigationItem.title = @"RA"; 

    // Add Background view 
    self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    // Add RAView 
    RAView *rAView = [[RAView alloc] initWithFrame:self.view.frame Controller:self]; 
    [self.view rAView]; 
} 

Quan điểm nó gọi (RAView) trông như thế này:

- (id)initWithFrame:(CGRect)frame Controller:(RAViewController *)Controller 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     // Initialization code 
     self.autoresizesSubviews = YES; 
     self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
     self.backgroundColor = [[UIColor alloc] initWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]; 

     controller = Controller; 

     // Draw Architecture View 
     [self drawArchitectureView]; 
    } 
return self; 
} 

-(void)drawArchitectureView { 
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, self.frame.size.width - 20, 50); 

    [button setBackgroundColor:[UIColor grayColor]]; 
    [button setTitle:@"Overview" forState:UIControlStateNormal]; 

    [self addSubview:button]; 
} 

Đối với một số lý do tôi không thể nhận mặt nạ tự động hóa để thay đổi kích thước chiều rộng nút khi thiết bị ở chế độ ngang. Bất kỳ trợ giúp nào cũng được đánh giá rất cao.

+1

Tôi tin rằng bạn sẽ cần phải thiết lập các autoresizingMask trên UIButton riêng của mình. –

+0

Đã thử điều đó. Nút đã kết thúc được di chuyển ra khỏi màn hình, đó không phải là những gì tôi mong đợi có nghĩa là tôi không thực sự hiểu nó hoạt động như thế nào. Ngoài ra không phải là điểm của 'self.autoresizesSubviews = YES;' vì vậy tôi không phải làm điều đó? –

+0

Bạn đã thử đặt các nút autoresizeMask thành gì? Bạn đã thử UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin? –

Trả lời

3

Nếu bạn muốn nó để giữ cùng một chiều cao, nhưng chỉ ở lại trung tâm đầy đủ, 10,0 từ bên trái và phải, hãy thử:

-(void)drawArchitectureView { 
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, self.frame.size.width - 20, 50); 

    button.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin; 

    [button setBackgroundColor:[UIColor grayColor]]; 
    [button setTitle:@"Overview" forState:UIControlStateNormal]; 

    [self addSubview:button]; 
} 
Các vấn đề liên quan