2010-08-23 137 views
0

我有一個viewcontroller設置爲scrollview委託(scrollview是viewcontroller的子視圖),當我把[scrollview removeFromSuperview]; viewcontroller和scrollview都被刪除,我只剩下一個空的窗口。我怎樣才能刪除滾動視圖?

如何只刪除滾動視圖?

編輯::::

這是我的ViewController的一部分.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位置!

+1

什麼語言,框架? – 2010-08-23 22:01:29

+0

iphone sdk對不起,我忘了 – user422241 2010-08-23 22:15:01

+0

你能發表一些代碼嗎?這裏沒有足夠的信息來給出合理的答覆。 – 2010-08-23 22:24:05

回答

0

基本上我之所以刪除然後添加我的滾動視圖是因爲當設備的方向改變爲風景我的風景子視圖在錯誤的地方(x,y)。

如果您在定位滾動視圖時遇到問題,應嘗試正確設置自動調整大小的遮罩或手動調整幀。沒有理由每次刪除並重新創建滾動視圖。

此外,在您列出的代碼中,您似乎泄漏了滾動視圖。

+0

漏水哪裏? – user422241 2010-08-24 00:37:58

+0

tiledLayer.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 不能做,tiledLayer不是結構或聯盟 – user422241 2010-08-24 00:48:01