转换所有子视图 [英] Transform all subviews

查看:52
本文介绍了转换所有子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在滚动视图中有一个UIView,其中包含大约100个子视图.子视图都看起来相同,并且是同一类的实例.我有一个要应用于每个子视图的变换.但是每次zoomScale更改时,变换都需要更改.

I have a UIView in a scrollview that contains about 100 subviews. The subviews all look the same and are instances of the same class. I have a transform that I want to apply to each subview. But the transform needs to change everytime zoomScale changes.

将变换应用于所有视图的最佳方法是什么?目前,我正在实现layoutSubviews,获取子视图数组,并将每个子视图的转换设置为新转换.

What's the best way to apply the transform to all the views? Currently Im implementing layoutSubviews, getting the array of subviews, and setting each subview's transform to the new transform.

有没有最佳的方法来做到这一点?

Is there an optimal way to do this?

更新:

我要转换的视图是地图上的图钉.当我使用scrollView放大时,它们需要按比例缩小(即,使用户看起来相同的大小),并保持锁定在相同的位置).

The views I want to transform are pins on a map. When I zoom in with scrollView they need to be scaled down (i.e. so they look the same size to the user) and remain locked to the same position).

- (void)layoutSubviews
{
    CGAffineTransform transform = CGAffineTransformMakeScale(1.0/self.zoomValue, 1.0/self.zoomValue);

    for(UIView *view in self.subviews){
        view.transform = transform;
    }    
}

...

- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
    self.mapMarkerContainer.zoomValue = scrollView.zoomScale;
    [self.mapMarkerContainer setNeedsLayout];
}

推荐答案

在对此进行了一些研究之后,发现我的初始方法是最有效的:

After a bit of research around this, it turns out that my initial method is the most efficient:

- (void)layoutSubviews
{
    CGAffineTransform transform = CGAffineTransformMakeScale(1.0/self.zoomValue, 1.0/self.zoomValue);

    for(UIView *view in self.subviews){
        view.transform = transform;
    }    
}

有时候,我想您只需要接受iPhone可以处理数据的速度方面的限制即可.

Sometimes I guess you just have to accept that there are limitations on how quick an iPhone can process data.

这篇关于转换所有子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆