2016-09-18 69 views
3

更新:这是一个iOS 10问题。这仍然可以在iOS 9中使用。iOS 10期:UIScrollView不滚动,即使设置ContentSize时

这是......有趣的。

我只是转换我的“教学计划”(“玩具”的应用程序),以斯威夫特3.

它一直致力于为雨燕1.2在一两年。

突然间,我的UIScrollView没有滚动,即使当我将contentSize方法设置为超越其下限时。

这里的有关代码(displayTags程序被调用与被显示为中心并且稍微垂直偏移图像的阵列,导致竖直链):

/*******************************************************************************************/ 
    /** 
     \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) 
    } 

注意,滚动视图的contentSize是每个扩展时间标签被添加。我检查了一下(看打印报告),这个值似乎是正确的。

The project itself is completely open-source.

This is where this issue manifests(我有其他错误,但在我这个钉子一个我会找固定它们)。

我敢肯定,我正在做一些明显的和骨头的事情(通常是这种情况)。

任何人有任何想法?

+0

我认为问题是与uiview,你没有设置高度.. – Do2

+0

我会检查出来。故事板中的高度已设置(并在构建时移除),但我不在此处设置。这是完全可能的,你是正确的。我发现在操作系统升级中,无证件(或未明确说明)的东西通常会发生变化。我只在iOS 10中测试过它。我想知道它是否会在iOS 9中再次运行?如果是这样,我还有另一个需要调整的应用程序。谢谢! –

+0

嗯,我刚刚检查出来。适用于9.3,但不适用于10.操作系统引入了曲线球。正在设置高度(请参阅我设置框架)。我需要弄清楚为什么iOS 10突然不喜欢这样。我在另一个应用中做了几乎完全相同的事情,我很担心。 –

回答

2

好的。我解决了它。

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

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

+0

你在运行时删除了每个约束并且成功了吗?除了使用Xamarin之外,我看到了同样的问题,在升级到IOS 10后,我的UIScrollView不再有高度。我可以垂直对齐我的直接子视图,它显示但不允许滚动。在ViewDidLoad中移除约束似乎并没有影响它。 – QckLrner

+1

TBH,我还没有完全想到这一点。这在那种情况下适用于我。但是,在其他情况下,我使用经典的结构,它的工作原理。我需要花一些时间尝试一些东西。 –

+0

我设置了一个演示Swift项目来测试这一点。 [这个项目](https://bitbucket.org/bmlt/testscroller)显示了这一点。 YMMV –

12

它会工作时,你会设置主线程contentSize并把这个代码- (void)viewDidLayoutSubviews

- (void)viewDidLayoutSubviews 
{ 
    dispatch_async (dispatch_get_main_queue(),^
        { 
         [self.scrollview setContentSize:CGSizeMake(0, 2100)]; 
        }); 
} 
+0

谢谢,我欣赏这个提示,并且给了它一个大拇指。不幸的是,虽然绝对正确,但这不是解决方案。问题在于,如果有顶级约束和主要约束,iOS 10突然开始将滚动视图固定到容器。我在构建时删除了这些内容,并解决了这个问题。再次,谢谢。 –

+0

谢谢,它解决了我的问题....! – Alessign

7

contentSize应在迅速主线变化。

DispatchQueue.main.async { 
     self.scrollView.contentSize = CGSize(width: 2000, height: 2000) 
    } 

这对我有效。

+0

这对我来说..这是绝对荒谬的,这不起作用从viewDidAppear – quantumpotato

+0

这也适用于我。我不得不提到的一点是,iPad上的行为似乎不同,因为在UI线程上设置contentSize可以很好地工作。 – VSG24

相关问题