UIScrollView 旋转
我有一个滚动视图,它自动生成一系列包含图像视图的子视图。这个概念是,它几乎是一个自定义的 PDF 样式阅读器,其中每个页面都作为图像加载到图像视图中。共有三个“层”——外部 UIScrollView、自动生成的子视图以及子视图内的 imageview。
我的困境是,当生成这些子视图时,它们实际上没有硬引用,因此在我的 didRotateFromInterfaceOrientation 中,无法说调整此特定视图的大小。
我创建了一个名为 setUpView 的函数,它按如下方式初始化所有视图和图像:
- (void)setUpView {
//INITIALISE PAGING SCROLL VIEW
CGRect pagingScrollViewFrame = [[UIScreen mainScreen] bounds];
pagingScrollViewFrame.origin.x -= 10;
pagingScrollViewFrame.size.width += 20;
pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
//CONFIGURE PAGING SCROLL VIEW
pagingScrollView.pagingEnabled = YES;
pagingScrollView.backgroundColor = [UIColor blackColor];
pagingScrollView.contentSize = CGSizeMake(pagingScrollViewFrame.size.width*7, pagingScrollViewFrame.size.height);
//ACTIVATE PAGING SCROLL VIEW
self.view = pagingScrollView;
//ADD PAGES TO SCROLL VIEW
for (int i = 0; i < 7; i++){
ImageScrollView *page = [[[ImageScrollView alloc] init] autorelease];
[self configurePage:page forIndex:i];
[pagingScrollView addSubview:page];
}
}
在我的 loadView 方法中,我只调用此函数。
有什么方法可以检测设备的当前方向,以便可以以某种方式输入到上述函数中?目前,在旋转时,外部视图旋转得很好,但内部子视图和图像视图却没有。
I have a scrollview that automatically generates a series of subviews containing imageviews. The concept is that it's pretty much a custom PDF style reader, where each page is loaded in to an imageview as an image. There are three "layers" - the outer UIScrollView, the automatically generated subViews and the imageview inside the subview.
My dilemma is that as these subviews are generated they don't really have a hard reference, so in my didRotateFromInterfaceOrientation there's no way to say resize THIS particular view.
I have created a function called setUpView which initialises all the views and images as so:
- (void)setUpView {
//INITIALISE PAGING SCROLL VIEW
CGRect pagingScrollViewFrame = [[UIScreen mainScreen] bounds];
pagingScrollViewFrame.origin.x -= 10;
pagingScrollViewFrame.size.width += 20;
pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
//CONFIGURE PAGING SCROLL VIEW
pagingScrollView.pagingEnabled = YES;
pagingScrollView.backgroundColor = [UIColor blackColor];
pagingScrollView.contentSize = CGSizeMake(pagingScrollViewFrame.size.width*7, pagingScrollViewFrame.size.height);
//ACTIVATE PAGING SCROLL VIEW
self.view = pagingScrollView;
//ADD PAGES TO SCROLL VIEW
for (int i = 0; i < 7; i++){
ImageScrollView *page = [[[ImageScrollView alloc] init] autorelease];
[self configurePage:page forIndex:i];
[pagingScrollView addSubview:page];
}
}
In my loadView method I just call this function.
Is there any way to detect the current orientation of the device so that may be fed into the above function somehow? At the moment, on rotate, the outerview rotates fine, but the inner sub-views and the imageviews do not.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使对象没有 UIDeviceOrientationDidChangeNotification 通知的参考观察者,该通知将在每次方向更改时发布。
然后,在您的orientationChanged:方法中,您可以检查当前方向并相应地布局您的视图。
来告诉设备生成此类通知!
但是,您需要通过调用“确保删除在 dealloc! 上观察方向变化的对象”
You can make the objects without reference observer for UIDeviceOrientationDidChangeNotification notification, which will be posted on every orientation change.
Then, in your orientationChanged: method you can check current orientation and layout your views accordingly.
However, you need to tell the device to generate such notifications by calling
Be sure to remove the objects that are observing the orientation change on dealloc!
您可以通过查看以下内容来获取设备方向:
或者您可以将 self.interfaceOrientation 用于 viewController。
You can get device orientation by looking at:
or you could use
self.interfaceOrientation
for viewController.