【发布时间】:2012-10-06 07:54:04
【问题描述】:
我在 UIScrollview 中添加 (400+) UIButtons,当我在 simulator 中滚动时,它运行良好,但在 iPad 中滚动缓慢。
Here's我在做什么。
- (void)viewDidLoad { [scrollView setContentSize:CGSizeMake(180 * 24 , 22 * 40 + 200)]; for (int e=0; e<12; e++) { for(int i=0;i<24;i++) { UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.titleLabel.font = [UIFont systemFontOfSize:12.0f]; [btn setBackgroundColor:[UIColor colorWithRed:248.0/255.0 green:248.0/255.0 blue:248.0/255.0 alpha:1]]; CALayer *layer = btn.layer; layer.cornerRadius = 5.f; layer.masksToBounds = YES; layer.borderWidth = 1.f; layer.borderColor = [[UIColor colorWithRed:190.0/255.0 green:190.0/255.0 blue:190.0/255.0 alpha:1] CGColor]; CGRect rect = btn.frame; rect.size.height = 40; rect.size.width = 50; rect.origin.x = 100 * i; rect.origin.y = 40 * e; btn.frame = rect; CAGradientLayer *shineLayer = [CAGradientLayer layer]; shineLayer.frame = layer.bounds; shineLayer.colors = [NSArray arrayWithObjects: (id)[UIColor colorWithWhite:0.9f alpha:0.5f].CGColor, (id)[UIColor colorWithWhite:0.9f alpha:0.7f].CGColor, (id)[UIColor colorWithWhite:0.9f alpha:1.f].CGColor, (id)[UIColor colorWithWhite:0.9f alpha:1.f].CGColor, (id)[UIColor colorWithWhite:0.9f alpha:1.f].CGColor,nil]; [layer addSublayer:shineLayer]; UILabel *lblDes = [[UILabel alloc] initWithFrame:CGRectMake(0,0,50,40)]; lblDes.backgroundColor = [UIColor clearColor]; lblDes.numberOfLines = 3; lblDes.textColor = [UIColor colorWithRed:4.0/255.0 green:106.0/255.0 blue:200.0/255.0 alpha:1]; lblDes.textAlignment = UITextAlignmentCenter; lblDes.text = @"adf"; lblDes.tag = -1; lblDes.font = [UIFont systemFontOfSize:11.f]; [btn addSubview:lblDes]; [scrollView addSubview:btn]; } } [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. }
【问题讨论】:
-
iOS模拟器比实际设备快,因为它使用计算机资源。
-
就像 Jossef 解释的那样,您无法将模拟器的速度与设备的速度进行比较。模拟器没有放慢速度来模拟ipad!因此,在设备上测试所有内容非常重要。如果真的有必要在屏幕上添加 400 多个 UIButton,我真的很感兴趣,这背后的情况是什么?
-
谢谢我看到了,但我不知道该怎么做?
标签: ios uiscrollview uibutton smooth-scrolling