【发布时间】:2017-01-26 09:36:36
【问题描述】:
更新:这是 iOS 10 的问题。这在 iOS 9 中仍然有效。
这……很有趣。
我刚刚将我的“教学项目”(一个“玩具”应用)转换为 Swift 3。
它在 Swift 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(我还有其他错误,但我会在解决这个问题后解决它们)。
我确信我正在做一些明显而愚蠢的事情(通常是这种情况)。
有人有什么想法吗?
【问题讨论】:
-
我认为问题出在uiview上,你没有设置高度..
-
我去看看。高度在情节提要中设置(并在构建时删除),但我没有在此处设置。你完全有可能是对的。我发现未记录(或未明确说明)的事情经常在操作系统升级中发生变化。我只在 iOS 10 中对此进行了测试。我想知道它是否会在 iOS 9 中再次运行?如果是这样,我还有另一个需要调整的应用程序。谢谢!
-
好吧,我刚刚检查过了。适用于 9.3,但不适用于 10。操作系统引入了曲线球。正在设置高度(请参阅我设置了框架)。我需要弄清楚为什么 iOS 10 突然不喜欢这个了。我在另一个应用程序中做几乎完全相同的事情,我很担心。
-
我试图将它设置在我的最后,但它是不可能的。你的 UIView 应该有一个明确的高度。通过测试,我看到 4-5 个标签工作正常,并且它滚动,但如果你有 20 个,你将无法看到它们。所以这并不是说你的滚动视图不滚动..
-
谢谢。我会继续戳它。就像我说的,它只在设备是 iOS 10 时发生,所以引擎盖下发生了一些变化。我以前在使用其他 SDK 时也发生过这种事情。
标签: ios iphone swift uiscrollview