2013-02-23 48 views
0

我正在創建一個文本笑話應用程序我需要的是我想要的UITextView刷卡形式就像當我滑動第一個笑話之後的差距另一個UITextview與另一個笑話進來,到目前爲止我所做的是我已經手動創建了UITextView(如果有10個笑話,然後是10個uitextview),並將它們添加到滾動中,但這需要花費太多時間在viewdidload方法中,並且該應用需要6,7秒才能加載... 如果您有任何其他想法請讓我知道在滑動上更改文本

for (int i = 0; i < arrresult.count; i++) { 




    CGRect frame; 
    frame.origin.x = self.scrollmain.frame.size.width * i; 
    frame.origin.y = 0; 
    frame.size = self.scrollmain.frame.size; 

    // UITextView *subview = [[UITextView alloc] initWithFrame:CGRectMake((frame.origin.x)+40,(frame.origin.y)+10, 230, 120)]; 
    // UITextView *subview2 = [[UITextView alloc]initWithFrame:CGRectMake((frame.origin.x)+40,(frame.origin.y)+160,230, 120)]; 

    UITextView *subview = [[UITextView alloc] initWithFrame:CGRectMake((frame.origin.x)+40,(frame.origin.y)+10, 230, 120)]; 
    UITextView *subview2 = [[UITextView alloc]initWithFrame:CGRectMake((frame.origin.x)+40,(frame.origin.y)+160,230, 120)]; 


    subview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"BG_text.png"]]; 
    subview2.backgroundColor = [UIColor whiteColor]; 

    [subview setFont:[UIFont boldSystemFontOfSize:14]]; 
    [subview2 setFont:[UIFont boldSystemFontOfSize:14]]; 

    subview.layer.cornerRadius = 10 ; 
    subview2.layer.cornerRadius = 10; 

    NSString *p = [duaobj2 dua_arabic]; 
    NSString *b = [duaobj2 eng_trans]; 

    subview.text = p; 
    subview2.text = b; 

    [self.scrollmain addSubview:subview]; 
    [self.scrollmain addSubview:subview2]; 

    subview.editable = NO; 
    subview2.editable = NO; 

    subview.textColor = [UIColor blackColor]; 
    subview2.textColor = [UIColor blackColor]; 


    subview.backgroundColor = [UIColor whiteColor]; 
    subview2.backgroundColor = [UIColor whiteColor]; 


    scrollmain.showsHorizontalScrollIndicator = NO; 

    CGRect frame1 = subview.frame; 
    CGRect frame2 = subview2.frame; 

    frame1.size.height = subview.contentSize.height; 
    frame2.size.height = subview2.contentSize.height; 

    subview.frame = frame1; 
    subview2.frame = frame2; 





} 


self.scrollmain.contentSize = CGSizeMake(self.scrollmain.frame.size.width * arrresult.count,self.scrollmain.frame.size.height); 

scrollmain.pagingEnabled = TRUE; 

scrollmain.delegate = self; 

回答

0

沒有必要加載子視圖時的viewDidLoad。

你應該通過使用scrollView委託方法來延遲這個。

您最多隻能創建3個文字視圖。當前,上一個和下一個。

在scrollViewDidScroll委託方法上,你應該明智地刪除以前加載的textview,你應該添加新的textview。

+0

非常感謝很多人...至少現在我有一個邏輯我會盡力實施 – 2013-02-23 06:20:00