好的,所以我有一个子类UIScrollView,里面有一些子视图,当设备方向改变时,我想更新子视图的位置,使它们适合新的方向。
当我刚刚更新子视图的位置然后转到滚动时,我注意到滚动句柄是巨大的...我的循环遍历所有子视图并更新了它们的帧也设置了滚动句柄的框架。 ..
所以为了解决这个问题......每当我添加子视图时,我都会在它们上面设置标签。当方向改变时,我的设置框架周围有条件,检查视图上的标签是否与我添加的子视图相匹配。如果是,则设置框架......
int i = 0;
for (UIView *gridViewItem in self.subviews) {
if (gridViewItem.tag == GRID_CELL) {
gridViewItem.frame = [self calculateCellPosition:i];
}
i++;
}
但是现在我想要检测子视图上的触摸,我想到的最简单的方法就是使用tag属性,这样我就知道正在点击哪个子视图...但是标签当前正被用于帮助我区分滚动手柄与其他子视图......
当我退出我的UIScrollView的子视图时,我得到了这个:
2011-05-08 16:07:56.266 XXXXXX[2096:207] (
"<UIView: 0x5a0d3f0; frame = (16 16; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a09250>>",
"<UIView: 0x5a19d70; frame = (167 16; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a17660>>",
"<UIView: 0x5a1d4f0; frame = (16 137; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a1d520>>",
"<UIView: 0x5a1e300; frame = (167 137; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a1e330>>",
"<UIView: 0x5a1e4f0; frame = (16 258; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a1e520>>",
"<UIView: 0x5a1f320; frame = (167 258; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a1f350>>",
"<UIView: 0x5a20120; frame = (16 379; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a20150>>",
"<UIView: 0x5a20fb0; frame = (167 379; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a20fe0>>",
"<UIView: 0x5a21dd0; frame = (16 500; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a21e00>>",
"<UIView: 0x5a22bb0; frame = (167 500; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a22be0>>",
"<UIView: 0x5a239a0; frame = (16 621; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a239d0>>",
"<UIView: 0x5a247b0; frame = (167 621; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a247e0>>",
"<UIView: 0x5a20f30; frame = (16 742; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a20f80>>",
"<UIView: 0x5a26460; frame = (167 742; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a26490>>",
"<UIView: 0x5a27220; frame = (16 863; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a27250>>",
"<UIView: 0x5a20dd0; frame = (167 863; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a28080>>",
"<UIView: 0x5a28e60; frame = (16 984; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a28e90>>",
"<UIView: 0x5a29c50; frame = (167 984; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a29c80>>",
"<UIView: 0x5a2aa60; frame = (16 1105; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a2aa90>>",
"<UIView: 0x5a2b870; frame = (167 1105; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a2b8a0>>",
"<UIView: 0x5a255a0; frame = (16 1226; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a255f0>>",
"<UIView: 0x5a262f0; frame = (167 1226; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a2d610>>",
"<UIView: 0x5a2e3c0; frame = (16 1347; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a2e3f0>>",
"<UIView: 0x5a2f1d0; frame = (167 1347; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a2f200>>",
"<UIView: 0x5a2ffc0; frame = (16 1468; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a2fff0>>"
)
所有子视图都有我的标签!我看不到滚动手柄?有没有人知道如何在不使用像我这样的标签的情况下识别滚动手柄?
非常感谢您的帮助!谢谢!
答案 0 :(得分:1)
我可能不会为此子类UIScrollView。将单个UIView添加到UIScrollView并将您的单元格添加到该视图。然后始终使用该视图。不需要标签,也不会干扰UIScrollViews的内部工作。只要内容视图的大小反映其中的单元格,滚动就应该有效。