我有一个滚动视图,它的初始化是这样的;
scrollV = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];稍后,我在应用程序中添加了一个UIView,我需要该UIView获取scrollView的高度和宽度。(因为scrollView的长度很长,所以我不能硬编码这个值)
所以我试了一下;
justAnotherView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.scrollV.frame.size.width, self.scrollV.frame.size.height)]; 但是,它没有采用滚动视图的大小(滚动视图的总大小)。它只显示屏幕的一部分(宽度320和高度460)。这是因为我上面写的scrollV初始化语句吗?我怎样才能纠正这个错误呢?
发布于 2011-12-30 02:37:50
您可能希望改用UIScrollView的contentSize属性。
... initWithFrame:CGMakeRect(0,0,scrollV.contentSize.width, scrollV.contentSize.height) ...发布于 2011-12-30 02:17:31
怎么样
justAnotherView = [[UIView alloc] initWithFrame:self.scrollV.frame];发布于 2011-12-30 02:35:18
我假设您已经将justAnotherView作为子视图添加到了scrollV中
就像您对justAnotherView所做的那样,您应该设置scrollV相对于其父对象的点和大小。它应该类似于:
scrollV = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,parent.frame.size.width,parent.frame.size.height)];https://stackoverflow.com/questions/8671631
复制相似问题