2013-05-09 33 views
0

我試圖建立使用CGFrame使用下面我CGFrame不顯示

- (void)viewDidLoad 
{ 
    [super viewDidLoad];  
    CGRect newFrame = [note_view frame]; 
    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) 
    newFrame.size.height += 223; 
    else 
    newFrame.size.height += 70; 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.2]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationCurve:UIViewAnimationOptionCurveEaseInOut]; 
    [note_view setFrame:newFrame]; 
    [UIView commitAnimations]; 

碼}的例子

- (void)loadView { 
    [super loadView]; 
    NSString *pupil; 
    UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(saveAndExit)]; 
    [[self navigationItem] setLeftBarButtonItem:done]; 
    UIBarButtonItem *date = [[UIBarButtonItem alloc] initWithTitle:@"Date Notes" style:UIBarButtonItemStyleBordered target:self action:@selector(dateNote)]; 
    [[self navigationItem] setRightBarButtonItem:date]; 
    [[self navigationItem] setTitle:@"Notes - " ]; 
    note_view = [[UITextView alloc] init]; 
    [note_view setBackgroundColor:[UIColor whiteColor]]; 
    [note_view setFont:[UIFont systemFontOfSize:17]]; 
    [[note_view layer] setCornerRadius:5]; 
    [[note_view layer] setBorderWidth:2]; 
    [[note_view layer] setBorderColor:[[UIColor colorWithRed:0.3882352941 green:0.6 blue:0.8117647059 alpha:1] CGColor]]; 
    [[note_view layer] setShadowOpacity:1]; 
    [[note_view layer] setShadowColor:[[UIColor colorWithRed:0.3882352941 green:0.6 blue:0.8117647059 alpha:1] CGColor]]; 
    [[note_view layer] setShadowRadius:10]; 
    [[note_view layer] setMasksToBounds:NO]; 

    [[self view] addSubview:note_view]; 
} 

的幀將不顯示,我只是得到了一個空白屏幕,我錯過了什麼?

回答

0

那麼我發現你的代碼中有一個問題。

問題:你沒有給出note_view的寬度,這意味着它取爲0這就是爲什麼你的note_view不可見一旦設置寬度並檢查它會來。

note_view.frame=CGRectMake(0, 0, 100, 10);

if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])){ 
     newFrame.size.height += 223; 
     newFrame.size.width = 100; 

    } 
    else 
    { 
     newFrame.size.height += 70; 
     newFrame.size.width = 100; 
    } 
+0

@ user616076:如果我的答案解決了ypur問題,請接受它。 – Balu 2013-05-09 16:03:22