Search Results

Search found 393 results on 16 pages for 'uiscrollview'.

Page 5/16 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • iPhone SDK UIScrollView doesn't get touch events after moving it

    - by newbie
    Hi! I'm subclassing UIScrollView and on the start I fill this ShowsScrollView with some items. After filling it, I setup frame and contentSize to this ShowsScrollView. Everything works fine for now, i get touches events, scrolling is working.. But after rotation to landscape, I change x and y coordinates of ShowsScrollView frame, to move it from bottom to top right corner. Then I resize it (change width and height of ShowsScrollView frame) and reorder items in this scroll. At the end I setup new contentSize. Now i get touches event only on first 1/4 of scrollview, scrolling also work only on 1/4 of scrollview, but scroll all items in scrollview. After all actions I write a log: NSLog(@"ViewController: setLandscape finished: size: %f, %f content: %f,%f",scrollView.frame.size.width,scrollView.frame.size.height, scrollView.contentSize.width, scrollView.contentSize.height ); Values are correct: ViewController: setLandscape finished: size: 390.000000, 723.000000 content: 390.000000,950.000000 On rotating back to portrait, I move and resize all thing back and everything works fine.. Please help!

    Read the article

  • iPhone: TableView inside UIScrollview, show vaccillating scrollbars around

    - by karim
    Hi, I have added some table and other vies in a scrollview. scrolling in tables are working fine. But in the parent scrollview, when scrolling, a vacillating vertical scrollbars are shown, sometimes it even come to the middle of the screen. sometime show at the left side of the screen. and not limited to the vertical scrollbar region. When I set tje showsVerticalScrollIndicator = NO, it is not shown. But do you know why the scrollbar is moving around. DashboardView is a subclass of UIScrollView. dashboard=[[DashboardView alloc] initWithFrame:fullScreenRect]; dashboard.contentSize = CGSizeMake(320,700); // must do! dashboard.showsVerticalScrollIndicator = YES; dashboard.bounces = YES; self.view = dashboard; @implementation DashboardView (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { // Initialization code } return self; } (void)drawRect:(CGRect)rect { // Drawing code } (void) layoutSubviews{ NSArray *views = self.subviews; [UIView beginAnimations:@"CollapseExpand" context:nil]; [UIView setAnimationDuration:0.5]; [UIView setAnimationBeginsFromCurrentState:YES]; [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; UIView *view = [views objectAtIndex: 0]; CGRect rect = view.frame; for (int i = 1; i < [views count]; i++ ) { view = [views objectAtIndex:i]; view.frame = CGRectMake(rect.origin.x, rect.origin.y + rect.size.height, view.frame.size.width, view.frame.size.height); rect = view.frame; } [UIView commitAnimations]; }

    Read the article

  • UIScrollview calling superviews layoutSubviews when scrolling?

    - by marchinram
    Hello, I added a UITableView as a subview to a custom UIView class I'm working on. However I noticed that whenever I scroll the table it calls my classes layoutSubviews. I'm pretty sure its the UIScrollview that the table is inheriting from which is actually doing this but wanted to know if there is a way to disable this functionality and if not why is it happening? I don't understand why when you scroll a scrollview it needs its superview to layout its subviews. Code: @implementation CustomView - (id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { self.clipsToBounds = YES; UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 15.0, 436.0, 132.0) style:UITableViewStylePlain]; tableView.dataSource = self; tableView.delegate = self; tableView.separatorStyle = UITableViewCellSeparatorStyleNone; tableView.backgroundColor = [UIColor clearColor]; tableView.showsVerticalScrollIndicator = NO; tableView.contentInset = UIEdgeInsetsMake(kRowHeight, 0.0, kRowHeight, 0.0); tableView.tag = componentIndex; [self addSubview:tableView]; [tableView release]; } return self; } - (void)layoutSubviews { // This is called everytime I scroll the tableview } @end

    Read the article

  • Obtaining touch location for a uiscrollview touch

    - by LOSnively
    I have a uiscrollview as an element of a uiscrollviewcontroller, along with other view objects. The image scrolls and zooms as expected, when the scrollView is the top subview. However, I also need to get the screen location of the touch, in particular when there is no scroll action. (I understand the location may change during a scroll, but that's not important.) I haven't found a way to do that. In the scrollviewcontroller implementation I have customized all of the standard methods that should do this: "touchesShouldBegin...", "touchesBegan:...", "touchesEnded:...", and so on. As far as I can tell, none of these are being called during a touch event when the scrollView is the top subview. I've tried setting the delayContentTouches property to both YES and NO, and that doesn't seem to make a difference. As an alternative, I've tried putting a UIView as the top subview and then tried passing the touches to the now underlying scrollView. In this configuration, the standard methods are called and I can get the touch location, but I haven't found a mechanism for the touches to be passed to the scrollView so scrolling occurs. Doing something like sending the touch messages to the specific scrollView, or to "super" or just sending them to nextResponder doesn't do it. It seems I can make the scroll work or find the location of the touch but not both, depending on what the "top" subview is. I suspect this is trivial, but after two weeks of struggling, it's time to eat my embarrassment for not being able to do this seemingly simplest of things. I've read all of the related questions here on stackoverflow, tried most if not all of the suggestions, and so far, nothing has worked. I've looked through the various links and references suggested by the answers, including Apple's documentation, but none have pointed out the gap in my understanding. Any ideas would be appreciated.

    Read the article

  • Can't touch UITextField on UIScrollView

    - by Chris B
    Hey guys, I know this has been talked about a lot. I think I've gone thru every question on this site, and still have not been able to get this working. I'm new to developing but I have a good sense of what's going on with all of my code. I definitely don't have a lot of experience though, this is my first iPhone app. I'm making a data entry field that is comprised of multiple UITextFields within a UIScrollView. I'll avoid explaining the other details for now, as it seems its a very basic problem. Without a scrollview, the textfields work perfectly. I can touch the textfield and the keyboard or picker view show up appropriately. When I add the textfields to a scrollview, the scrollview works, but then the text fields don't receive my touches. Here's the key: When 'User Interaction' is ENABLED, the scrollview works but the textfield touches are NOT registered. When 'User Interaction' is DISABLED, the scrollview doesn't work, but the textfield touches ARE registered and the keyboard/picker pops up. From the other posts I have seen people creating subclasses and overriding the touches in a separate implementation. I've seen people using custom content views (subviews?), I've seen some solutions that are now obsolete since the APIs have changed in newer versions of the SDK, and I am just completely stuck. I will leave out my code for now, because maybe there is a solution that someone has without requiring my code. If someone needs to see my code, I will put it up. My app is being written in the 3.1.3 SDK. If anyone has ANY information that could help, it would be so greatly appreciated.

    Read the article

  • laying out images in UIScrollView automatically

    - by Steve Jabs
    i have a list of images retrieved from xml i want to populate them to a uiscrollview in an order such that it will look like this. 1 2 3 4 5 6 7 8 9 10 if there is only 10 images it will just stop here. right now my current code is this for (int i = 3; i<[appDelegate.ZensaiALLitems count]-1; i++) { UIButton *zenbutton2 =[UIButton buttonWithType:UIButtonTypeCustom]; Items *ZensaiPLUitems = [appDelegate.ZensaiALLitems objectAtIndex:i]; NSURL *ZensaiimageSmallURL = [NSURL URLWithString:ZensaiPLUitems.ZensaiimageSmallURL]; NSLog(@"FVGFVEFV :%@", ZensaiPLUitems.ZensaiimageSmallURL); NSData *simageData = [NSData dataWithContentsOfURL:ZensaiimageSmallURL]; UIImage *itemSmallimage = [UIImage imageWithData:simageData]; [zenbutton2 setImage:itemSmallimage forState:UIControlStateNormal]; zenbutton2.frame=CGRectMake( (i*110+i*110)-660 , 300, 200, 250); [zenbutton2 addTarget:self action:@selector(ShowNextZensaiPage) forControlEvents:UIControlEventTouchUpInside]; [scrollView addSubview:zenbutton2]; } notice the CGRectMake , i have to manually assign fixed values to position them. Is there any way to populate them out without manually assigning. for e.g the images will automatically go down a position once the first row has 3 images and subsequently for the rest.

    Read the article

  • Paged UIScrollView with UIImageViews only showing first UIImageVIew

    - by Jonathan Brown
    I am working on a paged UIScrollView, but it only wants to show the first UIImageView within it. I add each UIImageView at an offset of the width of the scroll view, so that should create each page. When run, it says the scroll view is the right number of pages, but the images don't show. Any help would be much appreciated! int numSlides = NUM_TUTORIAL_SLIDES; NSString *fileName; UIImageView *slideImageView; CGRect slideFrame; for (int i = 1; i <= numSlides; i++) { slideFrame.origin.x = self.tutorialScrollView.frame.size.width * (i-1); slideFrame.origin.y = 0; slideFrame.size = self.tutorialScrollView.frame.size; slideImageView = [[UIImageView alloc] initWithFrame:slideFrame]; if([[AppManager sharedManager] is4inchScreen]) { fileName = [NSString stringWithFormat:@"Slide%[email protected]", i]; } else { fileName = [NSString stringWithFormat:@"Slide%[email protected]", i]; } slideImageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:nil]]; [self.tutorialScrollView addSubview:slideImageView]; [slideImageView release]; } self.tutorialScrollView.contentSize = CGSizeMake(self.tutorialScrollView.frame.size.width * numSlides, self.tutorialScrollView.frame.size.height); self.tutorialScrollView.delegate = self;

    Read the article

  • UIScrollView works as expected but scrollRectToVisible: does nothing

    - by mahboudz
    HI. I have used UIScrollView before, and am using it now, and never had a problem. I'm now adding it to an old app, and while it works as expected (I can look at the contents, scroll around with my finger, all the bounds and sizes are setup right so there is no empty space in the content, etc.), I just can't get scrollToRectVisible to work. I have even simplified the call so that it merely moves to the 0,0 position: [scrollView scrollRectToVisible:CGRectMake(0, 0, 10, 10) animated:YES]; or move it to 0,200: [scrollView scrollRectToVisible:CGRectMake(0, 200, 10, 10) animated:YES]; I even made a quick app to test this and I can get scrollRectToVisible to work there as I expect. But in my old app, I can't seem to make it do anything. I can make the scrollView scroll with setContentOffset:, but that's not what I want. This scrollView and its contents are defined in the nib by IB and used with an IBOutlet. The only code I am using in my app to handle the scrollView is [scrollView setContentSize:CGSizeMake(scrollView.contentSize.width, imageView.frame.size.height)]; (I'm only interested in vertical scrolling not horizontal). Has anyone run into a problem like this? I have compared the scrollView attributes in both apps and they are identical. ADDENDUM: My scrollViews frame is: 0.000000 0.000000 480.000000 179.000000 My scrollViews contentSize is: 0.000000 324.000000 It still acts like the rect I want to scroll to is already visible and no scrolling is needed. Not sure if that is what is happening. This is just the darnest thing. Seems like such an easy thing to resolve... ADDENDUM #2: This is how I am making do without scrollRectToVisible: CGPoint point = myRect.origin; if (![clefScrollView pointInside:point withEvent:nil]) { point.x = 0; if (point.y > clefScrollView.contentSize.height - clefScrollView.bounds.size.height) point.y = clefScrollView.contentSize.height - clefScrollView.bounds.size.height; [clefScrollView setContentOffset:point animated: YES]; } Everything else about this scrollView works as expected, but scrollRectToVisible. WHY?!? Any wild guesses?

    Read the article

  • UIScrollView Infinite Scrolling

    - by Ben Robinson
    I'm attempting to setup a scrollview with infinite (horizontal) scrolling. Scrolling forward is easy - I have implemented scrollViewDidScroll, and when the contentOffset gets near the end I make the scrollview contentsize bigger and add more data into the space (i'll have to deal with the crippling effect this will have later!) My problem is scrolling back - the plan is to see when I get near the beginning of the scroll view, then when I do make the contentsize bigger, move the existing content along, add the new data to the beginning and then - importantly adjust the contentOffset so the data under the view port stays the same. This works perfectly if I scroll slowly (or enable paging) but if I go fast (not even very fast!) it goes mad! Heres the code: - (void) scrollViewDidScroll:(UIScrollView *)scrollView { float pageNumber = scrollView.contentOffset.x / 320; float pageCount = scrollView.contentSize.width / 320; if (pageNumber > pageCount-4) { //Add 10 new pages to end mainScrollView.contentSize = CGSizeMake(mainScrollView.contentSize.width + 3200, mainScrollView.contentSize.height); //add new data here at (320*pageCount, 0); } //*** the problem is here - I use updatingScrollingContent to make sure its only called once (for accurate testing!) if (pageNumber < 4 && !updatingScrollingContent) { updatingScrollingContent = YES; mainScrollView.contentSize = CGSizeMake(mainScrollView.contentSize.width + 3200, mainScrollView.contentSize.height); mainScrollView.contentOffset = CGPointMake(mainScrollView.contentOffset.x + 3200, 0); for (UIView *view in [mainContainerView subviews]) { view.frame = CGRectMake(view.frame.origin.x+3200, view.frame.origin.y, view.frame.size.width, view.frame.size.height); } //add new data here at (0, 0); } //** MY CHECK! NSLog(@"%f", mainScrollView.contentOffset.x); } As the scrolling happens the log reads: 1286.500000 1285.500000 1284.500000 1283.500000 1282.500000 1281.500000 1280.500000 Then, when pageNumber<4 (we're getting near the beginning): 4479.500000 4479.500000 Great! - but the numbers should continue to go down in the 4,000s but the next log entries read: 1278.000000 1277.000000 1276.500000 1275.500000 etc.... Continiuing from where it left off! Just for the record, if scrolled slowly the log reads: 1294.500000 1290.000000 1284.500000 1280.500000 4476.000000 4476.000000 4473.000000 4470.000000 4467.500000 4464.000000 4460.500000 4457.500000 etc.... Any ideas???? Thanks Ben.

    Read the article

  • UIScrollView message handler

    - by cs221313
    Hi, all, I want to create a scroll view and put thumbnail view in that scroll view. but I can not get the touchBegan message in my program. My source code is like following. - (void)viewDidLoad { [super viewDidLoad]; NSError* error; NSString *bundleRoot = [[NSBundle mainBundle] bundlePath]; dirContents = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundleRoot error: &error] copy]; scrollView = [[UIScrollView alloc] initWithFrame:[[self view] bounds]]; scrollView.pagingEnabled = YES; scrollView.showsHorizontalScrollIndicator = NO; scrollView.userInteractionEnabled = YES; scrollView.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview scrollView.scrollEnabled = YES; [scrollView setDelegate:self]; [[self view] addSubview:scrollView]; DLog(@"scroll frame top = %d, left = %d, width = %d, height = %d", scrollView.frame.origin.x, scrollView.frame.origin.y, scrollView.frame.size.width, scrollView.frame.size.height); int i, j; UIView* onePageView = [[UIView alloc] init]; int pageNumber = 0; int iconNumber = 0; for (NSString *tString in dirContents) { if ([tString hasSuffix:@"_chess.png"]) { if(iconNumber == 9) { onePageView.tag = pageNumber + 1; [scrollView addSubview: onePageView]; onePageView = [[UIView alloc] init]; pageNumber++; iconNumber = 0; } j = iconNumber % 3; i = iconNumber / 3; const float WIDTH = 150.0; const float HEIGHT = 150.0; CGRect imageRect = CGRectMake(j * 200 + 50.0, i * 200 + 50.0, WIDTH, HEIGHT); //remove the charactors of "_chess.png". NSString* sgfName = [tString substringToIndex: tString.length - 10]; sgfName = [sgfName stringByAppendingString: @".sgf"]; ThumbnailView *thumbnailImage = [[ThumbnailView alloc] initWithFilename: sgfName frame: imageRect]; thumbnailImage.delegate = self; [thumbnailImage setImage:[UIImage imageNamed: tString]]; thumbnailImage.opaque = YES; // explicitly opaque for performance //[self.view addSubview:thumbnailImage]; [onePageView addSubview:thumbnailImage]; [thumbnailImage release]; iconNumber++; } } pageControl.numberOfPages = pageNumber + 1; pageControl.currentPage = 0; onePageView.tag = pageNumber + 1; [scrollView addSubview: onePageView]; [self layoutScrollPages]; } ThumbnailView class is like following. // // ThumbnailView.m // go // // Created by David Li on 2/18/11. // Copyright 2011 __MyCompanyName__. All rights reserved. // #import "common.h" #import "ThumbnailView.h" #import "ipad_goViewController.h" @implementation ThumbnailView @synthesize delegate; @synthesize sgfName; -(id) initWithFilename: (NSString*)filename frame: (CGRect)frame { sgfName = [[NSString alloc] initWithString: filename]; return [self initWithFrame: frame]; } - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code. self.userInteractionEnabled = YES; } return self; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self becomeFirstResponder]; } /* refer to http://stackoverflow.com/questions/855095/how-can-i-detect-the-touch-event-of-an-uiimageview */ -(BOOL)canBecomeFirstResponder { return YES; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { DLog(@"touched"); [[self delegate] loadGame: sgfName]; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code. } */ - (void)dealloc { [super dealloc]; } @end I can not catch the touchesBegan message in my program. Can anyone help me? I stucked by this problem by couple days. Thanks so much.

    Read the article

  • iphone uiscrollview and uiimageview - setting initial zoom

    - by Brodie4598
    I use the following code to load an image into an scroll view. The image always loads at 100% zoom. Is there a way to set it to load to another zoom level, say .37? UIImageView *tempImage = [[UIImageView alloc]initWithImage:[UIImage imageWithData:data]]; self.imageView = tempImage; scrollView.contentSize = CGSizeMake(imageView.frame.size.width , imageView.frame.size.height); scrollView.maximumZoomScale = 1; scrollView.minimumZoomScale = .37; scrollView.clipsToBounds = YES; scrollView.delegate = self; [scrollView addSubview:imageView];

    Read the article

  • UIScrollview setContentOffset immediate animation?

    - by Jess
    Is there anyway to get the setContentOffset animation to happen immediately instead of waiting until the app returns to the main run loop? I tried setting the animation property to NO and nesting inside of an animation block but it still waits until returning to the main run loop. I've also tried using a sub method to perform the animation. My problem is I perform some heavy work after setting the contentOffset so the scroll view waits until this work is complete to animate the setting of the content offset so it appears to lag for a second.

    Read the article

  • How To Detect "Touch Down" in superview of UIScrollView?

    - by wgpubs
    I have a UIView that contains a UIScrollView and I want to be able to capture the "Touch Down" event in the UIView any time the user taps on the UIScrollView. I've tried including all the touchesBegan/Ended/Cancelled handlers in my UIViewController but none of them get fired when tapping inside the UIScrollView contained in the main UIView. What is the best way to accomplish this?

    Read the article

  • [iPhone] Objective-C : UIScrollView manual paging

    - by Daniel
    Hi Folks! I want to use the scrollview as something like a picker in horizontal mode. The scrollview holds up to seven subviews. Each subview represents a value. Always three views are visible and the one in the middle is the selected one. Scrollview visible at start: __ | V1 | V2 Scrollview set to view/value two: V1 | V2 | V3 Scrollview set to last value: V2 | V3 | __ The real problem I have got is the "pagingEnabled" flag. If pagingEnabled is set to YES the scrollview pages always three subviews/values instead of only one. If pagingEnabled is set to NO the scrollview does not clinch. Is there a nice solution for my problem? Thanks a lot, Dan ;)

    Read the article

  • scroll image using UIscrollview

    - by summer
    i looked at the example from the iphone dev: http://developer.apple.com/iphone/library/samplecode/Scrolling/index.html everything looks cool except that for 5 image they set the "const NSUInteger kNumImages = 5;" what happens is that what if i have 1000 images?and i wan to view it without having to change the number everytime?also if i will to set the number to 1000 and i have only 10 images then in the simulator the user can scroll "blank view" till it reaches count 1000! help please..thanks

    Read the article

  • Uiscrollview displayed with focus at its center iphone sdk

    - by neha
    Hi all, I'm having a scrollview and a view over it both of which I'm creating through interface builder. But whenever I run the program the scrollview displays the part of the view which is almost at its center. It is scrollable, so when I pull it down, I can see the text in the view above but when I leave it's again positioned the earlier way i.e. somewhat down the actual (0,0) position. Can anybody hint me at the property which should be set in order to fix this?

    Read the article

  • Monotouch UIScrollView/UIPageView with UITableView as panel

    - by cvista
    Hi I'm building an app which is a guide to festivals. In the app I show lineups. You can see the Ui I have built for this on the video here: http://wmcstar.com/download.html The problem I have is that the scrollview/UIPageView - which does the left/right scrolling through the days, sometimes conflicts (i think) with the up/down scrolling of the days lineup UITableView and crashes. It doesn't crash if I disable scrolling - so the only way to switch between days is by selecting the day and programatically scrolling to the day rather than by using touch gestures. Has anyone else seen this behaviour? w://

    Read the article

  • Dynamically loading hi-res images into UIScrollView

    - by Jeff
    I've been looking into creating a gallery mode in my application. The functionality will be identical to the built in Photos App. Here's the flow: 1. You touch on a thumbnail and ... 2. a modal view displays a large detail version of the image 3. You have the ability to scroll horizontally through all the images in the gallery while in this modal view I'm stuck on step 3. How do I dynamically load hi res images into a scroll view? I understand I need to set the contentSize for the the scrollView but how do I do that when I've only selected and loaded one image? What delegate methods do I need to implement and what does the heavy lifting look like? Thanks in advance!

    Read the article

  • UIScrollView on scroll update method

    - by Alex Milde
    Hi is there a method / possibility to run a function when the scrollview is scrolling? i found scroll start and scroll end solutions but nothing like a onIsScrolling ... is there a built in solution? or whats the best workaround (nstimer)? thanks Alex

    Read the article

  • Play sound when UIScrollView is scrolling

    - by Chonch
    Hey, I have a scroll view that can be scrolled to the sides (only left and right, not up and down). I want to play a short sound (less than a second) whenever the scroll view is moved X pixels to either side. How can this be done? Code samples will be greatly appreciated... Thanks,

    Read the article

  • UIScrollView Custom View rotation problem

    - by Markus
    I have a ScrollView with a Custom View. Now i have the problem with the rotation, the view has after the rotation not the correct frame pos / size. How can i call the CustomView after rotation for a reposition and resize the frame and content?! - (void)setupPage { NSUInteger nimages = 0; CGFloat cx = 0; for (; ; nimages++) { if (nimages == list.count) { break; } CustomStepView *stepView = [[CustomStepView alloc] initWithFrame:CGRectZero]; stepView.tag = nimages; if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) { stepView.frame = CGRectMake(cx, 0.0 , 768.0f, 926.0f); cx += 768.0; } else { stepView.frame = CGRectMake(cx, 0.0 , 1024.0f, 670.0f); cx += 1024.0; } [scrollView addSubview:stepView]; [stepView release]; } self.pageControl.numberOfPages = nimages; }

    Read the article

  • Does UIScrollView have a special content view for making the scrolling possible?

    - by mystify
    I wonder if UIScrollView has got an "hidden" subview acting as an container for the content. If I scroll a scroll view, is that content view moved up/down in the scroll view? Or is the scrolling offset applied to the bounds of that UIScrollView instance? Or: Does UIScrollView use an additional view as container, or is all content added directly to the view? The documentation doesn't tell much about wether it has a content container or not.

    Read the article

  • How do I center a UIImageView within a full-screen UIScrollView?

    - by Sebastian Celis
    In my application, I would like to present the user with a full-screen photo viewer much like the one used in the Photos app. This is just for a single photo and as such should be quite simple. I just want the user to be able to view this one photo with the ability to zoom and pan. I have most of it working. And, if I do not center my UIImageView, everything behaves perfectly. However, I really want the UIImageView to be centered on the screen when the image is sufficiently zoomed out. I do not want it stuck to the top-left corner of the scroll view. Once I attempt to center this view, my vertical scrollable area appears to be greater than it should be. As such, once I zoom in a little, I am able to scroll about 100 pixels past the top of the image. What am I doing wrong? @interface MyPhotoViewController : UIViewController <UIScrollViewDelegate> { UIImage* photo; UIImageView *imageView; } - (id)initWithPhoto:(UIImage *)aPhoto; @end @implementation MyPhotoViewController - (id)initWithPhoto:(UIImage *)aPhoto { if (self = [super init]) { photo = [aPhoto retain]; // Some 3.0 SDK code here to ensure this view has a full-screen // layout. } return self; } - (void)dealloc { [photo release]; [imageView release]; [super dealloc]; } - (void)loadView { // Set the main view of this UIViewController to be a UIScrollView. UIScrollView *scrollView = [[UIScrollView alloc] init]; [self setView:scrollView]; [scrollView release]; } - (void)viewDidLoad { [super viewDidLoad]; // Initialize the scroll view. CGSize photoSize = [photo size]; UIScrollView *scrollView = (UIScrollView *)[self view]; [scrollView setDelegate:self]; [scrollView setBackgroundColor:[UIColor blackColor]]; // Create the image view. We push the origin to (0, -44) to ensure // that this view displays behind the navigation bar. imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, -44.0, photoSize.width, photoSize.height)]; [imageView setImage:photo]; [scrollView addSubview:imageView]; // Configure zooming. CGSize screenSize = [[UIScreen mainScreen] bounds].size; CGFloat widthRatio = screenSize.width / photoSize.width; CGFloat heightRatio = screenSize.height / photoSize.height; CGFloat initialZoom = (widthRatio > heightRatio) ? heightRatio : widthRatio; [scrollView setMaximumZoomScale:3.0]; [scrollView setMinimumZoomScale:initialZoom]; [scrollView setZoomScale:initialZoom]; [scrollView setBouncesZoom:YES]; [scrollView setContentSize:CGSizeMake(photoSize.width * initialZoom, photoSize.height * initialZoom)]; // Center the photo. Again we push the center point up by 44 pixels // to account for the translucent navigation bar. CGPoint scrollCenter = [scrollView center]; [imageView setCenter:CGPointMake(scrollCenter.x, scrollCenter.y - 44.0)]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[[self navigationController] navigationBar] setBarStyle:UIBarStyleBlackTranslucent]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [[[self navigationController] navigationBar] setBarStyle:UIBarStyleDefault]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES]; } - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return imageView; } @end

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >