简体   繁体   English

使滚动条在UIScrollView(iOS7)上始终可见?

[英]Make scrollbar always visible on UIScrollView (iOS7)?

Its possible to make UIScrollView indicator always show in iOS7? 是否可以使UIScrollView指示器始终在iOS7中显示? and not only when scrolling! 不仅在滚动时!

I've searched and cannot find a way to make it work. 我已经搜索过,无法找到使其工作的方法。

I've tried the code below but it does not work on iOS7 我已经尝试过下面的代码,但在iOS7上不起作用

#define noDisableVerticalScrollTag 836913
#define noDisableHorizontalScrollTag 836914

@implementation UIImageView (ForScrollView) 

- (void) setAlpha:(float)alpha {

    if (self.superview.tag == noDisableVerticalScrollTag) {
        if (alpha == 0 && self.autoresizingMask == UIViewAutoresizingFlexibleLeftMargin) {
            if (self.frame.size.width < 10 && self.frame.size.height > self.frame.size.width) {
                UIScrollView *sc = (UIScrollView*)self.superview;
                if (sc.frame.size.height < sc.contentSize.height) {
                    return;
                }
            }
        }
    }

    if (self.superview.tag == noDisableHorizontalScrollTag) {
        if (alpha == 0 && self.autoresizingMask == UIViewAutoresizingFlexibleTopMargin) {
            if (self.frame.size.height < 10 && self.frame.size.height < self.frame.size.width) {
                UIScrollView *sc = (UIScrollView*)self.superview;
                if (sc.frame.size.width < sc.contentSize.width) {
                    return;
                }
            }
        }
    }

    [super setAlpha:alpha];
}

@end

The code you've posted seems to be a category that overrides setAlpha on UIImageView , and checks the view's tag to see if it matches the expected tag for the UIScrollView indicator bars. 您发布的代码似乎是覆盖UIImageView setAlpha的类别,并检查视图的标记以查看其是否与UIScrollView指示条的预期标记匹配。 This is really hacky. 这真的很hacky。 You're relying on the tags remaining the same (which they invariably won't), and the indicator bars being UIImageView objects (which they may be now, but you have no guarantee of this in future iOS releases). 您所依赖的标记保持不变(它们始终不会那样),并且指示条是UIImageView对象(它们现在可能是,但您不能保证在将来的iOS版本中会做到这一点)。

You cannot set the scroll bar indicators in a UIScrollView to be permanently on - it's not supported in the API. 您无法将UIScrollView的滚动条指示器设置为永久打开-API不支持此功能。 Rather than try to mess around with the underlying architecture of the scroll view, if you really wanted to do this you would probably be better off implementing your own indicators. 如果您真的想这样做,而不是尝试弄乱滚动视图的基础体系结构,那么最好实现自己的指标。

This shouldn't be too difficult, since you know the size of the content in the scroll view, and you can also obtain the offset, so it's just a matter of creating two indicator views and moving them around as required (I say 'too difficult' - it's not easy, but it's a marginally more elegant solution than the code you've posted). 这应该不太困难,因为您知道滚动视图中内容的大小,并且还可以获得偏移量,因此只需创建两个指标视图并根据需要移动它们即可(我说“太困难”-这并不容易,但这是比您发布的代码稍微优雅的解决方案)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM