3

I have seen the WWDC-104 video showing UIScrollView for photos. I have downloaded the Sample code too. In my app the Structure is as follows,

(Root Class)Class A ---> Class B -----------> PhotoViewController(Containing ScrollView)

I am calling the PhotoViewController class by using presentModalViewController method in Class B.

But with every swipe the new Image shifts to right on the view. A black vertical strip is visible on left of the image which widens with each swipe. So after 6 to 8 images the view becomes totally black.

I have not written any other code. Just copied the classes.

Why this happens when the PhotoViewController class is not the first class to be loaded? Is there any property that needs to be set for ScrollView ? Is there any mistake in this view Hierarchy?

Also How to start from a particular image (Load from 10th image)?

Any help/suggestion will be highly appreciated.

EDIT :

alt text

After First Horizontal Swipe,

alt text

After Second Horizontal Swipe,

alt text

Roger_iPhone
  • 737
  • 1
  • 9
  • 20
  • I worked recently on this code so I can answer you. I'm not sure to understand your problem. You load PhotoViewController class in your app and when you swiper to another image you have a black strip ? can you show us an image ^^ ? – Vinzius Oct 04 '10 at 11:28
  • Hi I have added the images. The problem is when PhotoViewController is not the first class, first image loads correctly. After a swipe second image looks like its X coordinate is shifted. For third image X coordinate is further shifted. But I have not changed anything in code and same code works great when PhotoViewController is first class loaded. What can be the problem? – Roger_iPhone Oct 05 '10 at 03:26

2 Answers2

4

Isn't your PhotoViewController pushed by a UINavigationController when you use it in your application ?

That's the problem, the NavigationController modifies the frame of the ScrollView and the offset and extended width created by PhotoViewController is not longer there once the view appears.

The easiest way to fix this is to set the view of PhotoViewController to a regular UIView and add the ScrollView as a subview of this UIView. Then the NavigationController will modify the frame of this view but it will not touch the subview.

UIView * intermediateView = [[UIView alloc] initWithFrame:pagingScrollViewFrame];
[intermediateView addSubview:pagingScrollView];
self.view = intermediateView;

Have a look at this question for more info: Photos app-like gap between pages in UIScrollView with pagingEnabled

Community
  • 1
  • 1
Gautier
  • 111
  • 6
  • Instead of Pushing the controller using addSubview solves the problem. However I am not able to detect UITouch events now.. – Roger_iPhone Dec 21 '10 at 11:27
0

it sounds like you may not be taking the inter-image margin into account. Did you also copy their resource files? If I recall correctly, their scrollview extended 'off the page' a bit to give a margin between images.

Ben Gottlieb
  • 85,404
  • 22
  • 176
  • 172
  • Yes..The margin is there between images but it is done programatically and code is there for that. Problem is same app runs perfectly when my first class is PhotoViewController but when when I call it from some other button click then this problem occurs. – Roger_iPhone Oct 05 '10 at 03:00