【发布时间】:2012-02-05 14:39:29
【问题描述】:
我有一个 UIView 的子类,称为 PinView,其中包含一个图像。基本上 PinView 被多次添加到我的应用程序中,然后我对 PinView 对象执行转换。问题是当我添加大量 PinView 时,我的应用会变得迟缓,因为我正在转换每个 PinView。
理想情况下,我希望将一个“静态”PinView 多次添加到 UIView 中,但我只需转换一次。目前这似乎不起作用。每次我将静态 PinView 添加到我的 UIView 时,它只会在 UIView 中出现一次(因为我猜它只能有一个超级视图)。
我很难找到解决此问题的最佳方法 - 我如何使用指向 PinView 的单个指针,将其多次添加到 UIView 并能够对传递的 PinView 执行转换到我的 UIView 中显示的 PinViews? (顺便说一下,所有 PinView 的变换总是相同的)。
我假设这将是提高性能的最佳方式,如果不是这样,请告诉我。
更新:
- (void)layoutSubviews
{
CGAffineTransform transform = CGAffineTransformMakeScale(1.0/self.zoomValue, 1.0/self.zoomValue);
NSMutableArray *mut = nil;
PinView *pinView = nil;
CallOutView *callOut = nil;
//get all dictionary entries
for(NSString *identifier in self.annotationsDict.allKeys){
//get the array from dictionary
mut = [(NSArray *)([self.annotationsDict objectForKey:identifier]) mutableCopy];
//change layout if not nil
if([[mut objectAtIndex:PIN] isKindOfClass:[PinView class]]){
pinView = ((PinView *)[mut objectAtIndex:PIN]);
pinView.transform = transform;
[mut replaceObjectAtIndex:PIN withObject:pinView];
}
if([[mut objectAtIndex:CALL_OUT] isKindOfClass:[CallOutView class]]){
callOut = ((CallOutView *)[mut objectAtIndex:CALL_OUT]);
callOut.transform = transform;
[mut replaceObjectAtIndex:CALL_OUT withObject:callOut];
if(pinView !=nil)callOut.center = CGPointMake(pinView.center.x, pinView.center.y - pinView.frame.size.height);
}
[self updateAnnotationsKey:identifier forObject:[NSArray arrayWithArray:mut]];
mut = nil;
pinView = nil;
callOut = nil;
}
}
更新:
删除了上面的,现在只有:
- (void)layoutSubviews
{
CGAffineTransform transform = CGAffineTransformMakeScale(1.0/self.zoomValue, 1.0/self.zoomValue);
for(UIView *view in self.subviews){
view.transform = transform;
}
}
【问题讨论】:
标签: iphone objective-c ios uiview