iOS 10问题:即使设置了ContentSize,UIScrollView也不会滚动 [英] iOS 10 Issue: UIScrollView Not Scrolling, Even When ContentSize Is Set

查看:384
本文介绍了iOS 10问题:即使设置了ContentSize,UIScrollView也不会滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:这是iOS 10问题。这仍然像以前一样在iOS 9中运行。



这是......很有趣。



我刚刚把我的教学项目(一个玩具应用程序)转换为Swift 3。



它在Swift 1.2下工作了几年。



突然间,我的UIScrollView没有滚动,即使我将contentSize设置为超出其下边界。



这是相关的代码(displayTags例程使用一组图像调用,这些图像以居中和略微垂直偏移的方式显示,导致垂直链):

  / ******************************************** *********************************************** / 
/ **
\ brief在滚动视图中显示标签。

\ param inTagImageArray要显示的标记图像数组。
* /
FUNC displayTags(inTagImageArray:[UIImage的])!
{
self.tagDisplayView .bounds = self.tagDisplayScroller .bounds
如果(inTagImageArray.count > 0)//我们需要显示图像
{
var offset:CGFloat = 0.0 //这将是每个标记的垂直偏移量。

inTagImageArray中的标签
{
self.displayTag(inTag:tag,inOffset:& offset)
}
}
}
/ ********************************************* ********************************************** /
/ **
\ brief在滚动视图中显示单个标签。

\ param inTag要显示的标签的UIImage。
\ param inOffset要绘制的标记的垂直偏移量(从显示视图的顶部开始)。
* /
FUNC displayTag(inTag:的UIImage,inOffset:INOUT CGFloat的)
{
设ImageView的:的UIImageView =的UIImageView(图像:inTag)
VAR containerRect:的CGRect = self.tagDisplayView!.frame //了解我们必须使用的内容。
containerRect.origin = CGPoint.zero
让targetRect:的CGRect =的CGRect(X:(containerRect.size.width - inTag.size.width)/ 2.0,Y:inOffset,宽度:inTag.size。宽度,高度:inTag.size.height)
imageView.frame = targetRect
containerRect.size.height = MAX((targetRect.origin.y + targetRect.size.height),(containerRect.origin。 Y + containerRect.size.height))
self.tagDisplayView!.frame = containerRect
self.tagDisplayView!.addSubview(ImageView的)
self.tagDisplayScroller!.contentSize = containerRect.size
print(Tag Container Rect:\(containerRect))
print(Tag ScrollView Bounds:\(self.tagDisplayScroller!.bounds))
inOffset = inOffset +(inTag。 size.height * 0.31)
}

请注意,每次滚动时,scrollView的contentSize都会扩展标签已添加。我检查了(看打印语句),值似乎是正确的。



项目本身是完全开源的。



这是此问题舱单(我还有其他的错误,但是在我指出这个错误之后我会解决它们。)



我确定我在做某事明显的和愚蠢的(通常是这种情况)。



任何人都有任何想法吗?

解决方案

行。我解决了它。



我在构建时删除内部(滚动)视图的每个自动布局约束。



<我假设iOS 10终于通过强制滚动视图的顶部附加到滚动条的顶部来表达合同,即使用户想要移动它。


UPDATE: This is an iOS 10 issue. This still works as before in iOS 9.

This is ...interesting.

I just converted my "teaching project" (a "toy" app) to Swift 3.

It has been working for a couple of years under Swift 1.2.

All of a sudden, my UIScrollView is not scrolling, even when I set the contentSize way past its lower boundary.

Here's the relevant code (the displayTags routine is called with an array of images that are displayed centered and slightly vertically offset, leading to a vertical chain):

    /*******************************************************************************************/
    /**
        \brief  Displays the tags in the scroll view.

        \param inTagImageArray the array of tag images to be displayed.
    */
    func displayTags ( inTagImageArray:[UIImage] )
    {
        self.tagDisplayView!.bounds = self.tagDisplayScroller!.bounds
        if ( inTagImageArray.count > 0 )    // We need to have images to display
        {
            var offset:CGFloat = 0.0    // This will be the vertical offset for each tag.

            for tag in inTagImageArray
            {
                self.displayTag ( inTag: tag, inOffset: &offset )
            }
        }
    }
    /*******************************************************************************************/
    /**
        \brief  Displays a single tag in the scroll view.

        \param inTag a UIImage of the tag to be displayed.
        \param inOffset the vertical offset (from the top of the display view) of the tag to be drawn.
    */
    func displayTag ( inTag:UIImage, inOffset:inout CGFloat )
    {
        let imageView:UIImageView = UIImageView ( image:inTag )
        var containerRect:CGRect = self.tagDisplayView!.frame   // See what we have to work with.
        containerRect.origin = CGPoint.zero
        let targetRect:CGRect = CGRect ( x: (containerRect.size.width - inTag.size.width) / 2.0, y: inOffset, width: inTag.size.width, height: inTag.size.height )
        imageView.frame = targetRect
        containerRect.size.height = max ( (targetRect.origin.y + targetRect.size.height), (containerRect.origin.y + containerRect.size.height) )
        self.tagDisplayView!.frame = containerRect
        self.tagDisplayView!.addSubview ( imageView )
        self.tagDisplayScroller!.contentSize = containerRect.size
        print ( "Tag Container Rect: \(containerRect)" )
        print ( "    Tag ScrollView Bounds: \(self.tagDisplayScroller!.bounds)" )
        inOffset = inOffset + (inTag.size.height * 0.31)
    }

Note that the scrollView's contentSize is expanded each time a tag is added. I checked (see the print statements), and the value seems to be correct.

The project itself is completely open-source.

This is where this issue manifests (I have other bugs, but I'll get around to fixing them after I nail this one).

I'm sure that I am doing something obvious and boneheaded (usually the case).

Anyone have any ideas?

解决方案

OK. I solved it.

I remove every single auto layout constraint for the internal (scrolled) view at build time.

I assume that iOS 10 is finally honoring the contract by forcing the top of the scrolled view to attach to the top of the scroller, even though the user wants to move it.

这篇关于iOS 10问题:即使设置了ContentSize,UIScrollView也不会滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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