Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-07-2011, 02:23 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 1
nsawotin is on a distinguished road
Default Seeing large area of UIScrollView background when zoomed-in & pan down

Problem:
The problem I’m having is when I zoom into my UIScrollView (with paging enabled), and then I pan down – I can drag well past my view and see a large area of the scrollview’s background. The further I'm zoomed-in, the more of the UIScrollView's background is exposed. (I have set the scrollview's background to green so I can tell what I’m looking at).

Not sure why the background area is exposed like that...?

I've played around with setting the scrollview's frame size, bounds size, content size etc. in various locations to no avail. Seems I am missing something simple.

Further details:
My app’s main view contains a full-screen sized UIScrollView populated with a number of UIView subviews. These subviews are added to the scrollview by creating the nib names in a for loop, and then retrieving them using the loadNibNamed method to create & add the UIView.

Each of these UIViews were designed in IB and contain the following: A UIImageView whose image attribute is set to a .jpg image, another smaller UIScrollView below that, and a transparent UIView over top of my imageview which contains a bunch of custom UIButtons.

After I populate my scrollView, I set some of it’s attributes such as contentSize, pagingEnabled, min & maxZoomScale, etc. & then set it’s delegate to self (MainViewController).

MainViewController's relevant methods:

Code:
@implementation MainViewController_iPhone

@synthesize scrollView, loadedNibView;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {   
    [super viewDidLoad];
    [self loadNibs];
    [self initializeOrientation];
}

-(void) loadNibs {
    currentPage = 0;

    for (int i = 0; i < NUM_VIEWS; i++) {
        loadedNibView = [self getNibView:i];        //load the UIView from the associated nib file
        loadedNibView.tag = i;                      //used later to retrieve view for current page
        [scrollView addSubview:loadedNibView];
    }

    //Set the content size to sum of the widths of the all UIViews
    scrollView.contentSize = CGSizeMake(self.view.frame.size.width * NUM_VIEWS, self.view.frame.size.height);
    scrollView.pagingEnabled = YES;
    scrollView.bounces = YES;
    scrollView.clipsToBounds = YES;                 
    //scrollView.alwaysBounceVertical = YES;

    //zoom features
    scrollView.maximumZoomScale = 5.0;
    scrollView.minimumZoomScale = 1;                

    scrollView.delegate = self;                     
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)myScrollView {   
    return [myScrollView viewWithTag:(currentPage)];
}

- (void)scrollViewDidScroll:(UIScrollView *)myScrollView {
    CGFloat pageWidth = myScrollView.frame.size.width;
    currentPage = floor((myScrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
}

- (void)scrollViewDidZoom:(UIScrollView *)myScrollView {
}

- (void)scrollViewWillBeginZooming:(UIScrollView *)myScrollView withView:(UIView *)view
{   
    //zooming & paging do not work well together; disable paging while we're zooming
    myScrollView.pagingEnabled = NO;
}

- (void)scrollViewDidEndZooming:(UIScrollView *)myScrollView withView:(UIView *)view atScale:(float)scale  
{   
    if(scale == 1)  //if we're zoomed entirely back out
    {
    //re-enable paging & reset the content size
    myScrollView.pagingEnabled = YES;
    scrollView.contentSize = CGSizeMake(self.view.frame.size.width * NUM_VIEWS, self.view.frame.size.height);  //without this line, can no longer page through scrollview after zooming
    }
} 


@end
And it's .h:

Code:
@interface MainViewController_iPhone : MainViewController <UIScrollViewDelegate> {  
    IBOutlet UIScrollView *scrollView;          //The main ScrollView that scrolls between pages of different images to search
    UIView *loadedNibView;                      //The UIView that we load from it's corresponding nib (i.e. IMG1_iPhone.xib)
    int currentPage;
}

//methods
-(void) loadNibs;
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)myScrollView;
- (void)scrollViewWillBeginZooming:(UIScrollView *)myScrollView withView:(UIView *)view;
- (void)scrollViewDidEndZooming:(UIScrollView *)myScrollView withView:(UIView *)view atScale:(float)scale;
- (void)scrollViewDidZoom:(UIScrollView *)myScrollView;
- (void)scrollViewDidScroll:(UIScrollView *)myScrollView;

//properties
@property (nonatomic, retain) UIScrollView *scrollView;
@property (nonatomic, retain) UIView *loadedNibView;

@end
Any ideas/advice would be greatly appreciated...Thanks!
Attached Images
File Type: jpg Screen shot 2011-03-04 at 11.58.17 AM.jpg (4.7 KB, 7 views)
File Type: jpg Screen shot 2011-03-04 at 12.56.38 PM.jpg (8.1 KB, 4 views)
nsawotin is offline   Reply With Quote
Reply

Bookmarks

Tags
background, ios, iphone, uiscrollview, zoom

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 363
17 members and 346 guests
Absentia, akphyo, apatsufas, BinHex, dre, fredidf, Gaz, gmarro, host number one, jeroenkeij, Kirkout, MarkC, mottdog, Music Man, PavelMik, whitey99, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:21 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0