Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 7, 2011, 03:38 PM   #1
nsawotin
macrumors newbie
 
Join Date: Mar 2011
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 Thumbnails
Click image for larger version

Name:	Screen shot 2011-03-04 at 11.58.17 AM.png
Views:	70
Size:	32.9 KB
ID:	274804   Click image for larger version

Name:	Screen shot 2011-03-04 at 12.56.38 PM.png
Views:	50
Size:	37.0 KB
ID:	274805  
nsawotin is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
scrolling a UIScrollView on the click of a button ashwinr87 iPhone/iPad Programming 2 Jun 17, 2011 01:00 PM
drag images in & out of UIScrollview BarryK88 iPhone/iPad Programming 3 Mar 23, 2011 05:49 AM
UIScrollView - after zoom inner content auto moves to top left corner of UIScrollView springframework iPhone/iPad Programming 9 Aug 27, 2008 12:14 AM
Change look of CD background when opened? ITASOR Mac Programming 3 Aug 22, 2005 02:15 PM


All times are GMT -5. The time now is 09:44 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC