我有一个设置为滚动视图委托的视图控制器(滚动视图是视图控制器的子视图),当我放置 [scrollview removeFromSuperview]; viewcontroller 和 scrollview 都被删除了,我只剩下一个空窗口。
如何仅删除滚动视图?
编辑::::
这是我的视图控制器 .h 的一部分
@interface QuartzViewController : UIViewController <UIScrollViewDelegate> {
这是我的视图控制器 .m 的一部分
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
UIInterfaceOrientation o = self.interfaceOrientation;
if ((o == UIInterfaceOrientationPortrait) || (o == UIInterfaceOrientationPortraitUpsideDown)) {D = 1;pagingScrollView.delegate = nil;[pagingScrollView removeFromSuperview];[self resurrectPaging];}
if ((o == UIInterfaceOrientationLandscapeLeft) || (o == UIInterfaceOrientationLandscapeRight)) {D = 2;pagingScrollView.delegate = nil;[pagingScrollView removeFromSuperview];[self resurrectPaging];}}
-(void)resurrectPaging {
CGRect F;
F = [self frameForPagingScrollView];
pagingScrollView = [[UIScrollView alloc] initWithFrame:F];
[SELF addSubview:pagingScrollView];
[self setPaging];}
- (void)viewDidLoad {
[self.view addSubview:SELF];
D = 1;
CGRect F;
F = [self frameForPagingScrollView];
pagingScrollView = [[UIScrollView alloc] initWithFrame:F];
[self setPaging];}
- (void)setPaging {
if (D == 1) {
CGRect F;
F = [self frameForPagingScrollView];
pagingScrollView.pagingEnabled = YES;
pagingScrollView.backgroundColor = [UIColor whiteColor];
pagingScrollView.showsVerticalScrollIndicator = NO;
pagingScrollView.showsHorizontalScrollIndicator = NO;
pagingScrollView.contentSize = CGSizeMake(F.size.width * [self pdfPageCount], F.size.height);
pagingScrollView.delegate = self;
pagingScrollView.clipsToBounds = YES;
pagingScrollView.bounces = YES;
self.view = pagingScrollView;
recycledPages = [[NSMutableSet alloc] init];
visiblePages = [[NSMutableSet alloc] init];
[self tilePages];
[pagingScrollView addSubview:self.isvP];}
else if (D == 2) {
CGRect F;
F = [self frameForPagingScrollView];
pagingScrollView.pagingEnabled = YES;
pagingScrollView.backgroundColor = [UIColor redColor];
pagingScrollView.showsVerticalScrollIndicator = NO;
pagingScrollView.showsHorizontalScrollIndicator = NO;
pagingScrollView.contentSize = CGSizeMake(F.size.width * [self pdfPageCount], F.size.height);
pagingScrollView.delegate = self;
pagingScrollView.clipsToBounds = YES;
pagingScrollView.bounces = YES;
self.view = pagingScrollView;
recycledPages = [[NSMutableSet alloc] init];
visiblePages = [[NSMutableSet alloc] init];
[self tilePages];
[pagingScrollView addSubview:self.isvL];}}
基本上我要删除然后再次添加我的滚动视图的原因是因为当设备方向更改为横向时,我的横向子视图位于错误的位置(x,y)。
但是说如果我从横向开始 isvL 是在正确的地方,所以我知道我的代码是正确的。在我的 pagingScrollView 中横向拧紧 isvL 的 x、y 位置!