【发布时间】:2012-03-31 23:24:51
【问题描述】:
这是我的程序:
我有缓存变量@property (nonatomic, retain) NSMutableDictionary *cache;,用于存储我的 UIImageViews。图片尺寸为768 × 1024。
UIImageView *cap_1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"face1_cap_0.png"]];
[self.cache setObject:cap_1
forKey:@"cap_1"];
[cap_1 release];
UIImageView *cap_2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"face1_cap_1.png"]];
[self.cache setObject:cap_2
forKey:@"cap_2"];
[cap_2 release];
UIImageView *cap_3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"face1_cap_2.png"]];
[self.cache setObject:cap_3
forKey:@"cap_3"];
[cap_3 release];
UIImageView *cap_4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"face1_cap_3.png"]];
[self.cache setObject:cap_4
forKey:@"cap_4"];
[cap_4 release];
UIImageView *cap_5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"face1_cap_4.png"]];
[self.cache setObject:cap_5
forKey:@"cap_5"];
[cap_5 release];
UIImageView *cap_6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"face1_cap_5.png"]];
[self.cache setObject:cap_6
forKey:@"cap_6"];
[cap_6 release];
我在 PanGesture 中使用 UIImageViews,每滑动 50 pt 我在我的主视图上添加每个 UIImageView。我只在第一次滞后,然后在主视图上添加所有 UIImageViews,但在其他所有时间它工作得很快。如何优化第一次滑动?或者请告诉我另一种方法。
【问题讨论】:
-
你什么时候初始化你的 UIImageViews ?他们在刷卡之前是否设置为另一个超级视图?
-
不,他们没有,我只将它们存储在 NSMutableDictionary 中。
标签: ios ipad caching optimization uiimageview