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;
4

1 回答 1

0

在 viewDidLoad 时不需要加载子视图。

您应该使用 scrollView 委托方法来延迟这一点。

您应该最多只创建 3 个文本视图。当前,上一个和下一个。

在 scrollViewDidScroll 委托方法上,您应该明智地删除以前加载的 textview 并添加新的 textview。

于 2013-02-23T06:14:06.293 回答