如何仅删除scrollview?

时间:2010-08-23 21:55:38

标签: iphone scrollview

我有一个设置为scrollview委托的viewcontroller(scrollview是viewcontroller的子视图),当我把[scrollview removeFromSuperview];视图控制器和滚动视图都被删除了,我只剩下一个空窗口。

如何仅删除滚动视图?

编辑::::

这是我的viewcontroller .h

的一部分
@interface QuartzViewController : UIViewController <UIScrollViewDelegate> {

这是我的viewcontroller .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位置!

1 个答案:

答案 0 :(得分:0)

  

基本上我删除什么然后再添加我的滚动视图的原因是因为当设备方向更改为横向时,我的横向子视图位于错误的位置(x,y)。

如果您在定位滚动视图时遇到问题,则应尝试正确设置自动调整大小的遮罩,或手动调整框架。没有理由每次都删除并重新创建滚动视图。

此外,在您列出的代码中,您似乎正在泄露滚动视图。