UIScrollView Custom Paging?

I just did this for another project. What you need to do is to place the UIScrollView into a custom implementation of UIView. I created a class for this called ExtendedHitAreaViewController.

The ExtendedHitAreaView overrides the hitTest function to return its first child object, which will be your scroll view.

Up vote 3 down vote favorite share g+ share fb share tw.

My question has to do with a custom form of paging which I am trying to do with a scroller, and this is easier to visualise if you first consider the type of scroll view implemented in a slot machine. So say my UIScrollView has a width of 100 pixels. Assume it contains 3 inner views, each with a width of 30 pixels, such that they are separated by a width of 3 pixels.

The type of paging which I would like to achieve, is such that each page is one of my views (30 pixels), and not the whole width of the scroll view. I know that usually, if the view takes up the whole width of the scroll view, and paging is enabled then everything works. However, in my custom paging, I also want surrounding views in the scroll view to be visible as well.

How would I do this? Iphone objective-c uiview uiscrollview link|improve this question asked Aug 4 '11 at 17:33Olshansk665 83% accept rate.

Can you use UIPickerView?. It does this paging stuff. – user745098 Aug 4 '11 at 17:42 1 Check out Beginning iPhone Development by Mark & laMarche - it has a section on creating a slot machine from a UIPickerView - it's not a UIScrollView but maybe this will do what you want?

– amergin Aug 4 '11 at 18:26 I looked into UIPickerViews, and I spent quite a bit of time trying to make it horizontal and doing other customizations to fit my needs. However, the limitation of not being able to change the height (no matter how hard I tried) does not allow me to do some of the things I'm trying. What I practically need to do is get a customizable UIScrollView.

At the moment I'm trying to cheat my way through by having several UIScrollViews beside each other, and set off their contents appropriately. – Olshansk Aug 4 '11 at 20:36.

I just did this for another project. What you need to do is to place the UIScrollView into a custom implementation of UIView. I created a class for this called ExtendedHitAreaViewController.

The ExtendedHitAreaView overrides the hitTest function to return its first child object, which will be your scroll view. Your scroll view should be the page size you want, i.e. , 30px with clipsToBounds = NO.

The extended hit area view should be the full size of the area you want to be visible, with clipsToBounds = YES. Add the scroll view as a subview to the extended hit area view, then add the extended hit area view to your viewcontroller's view. @implementation ExtendedHitAreaViewContainer - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { if (self pointInside:point withEvent:event) { if (self subviews count > 0) { //force return of first child, if exists return self subviews objectAtIndex:0; } else { return self; } } return nil; } @end.

Amazing! This did exactly what I was trying to achieve. Before I saw this answer, I had actually almost completed my implementation which involved having 3 scrollviews (because I only wanted to have 3 items visible at a time), and I would set their content offset appropriately when any one of the 3 scrollvies was scrolled.

It kind of worked but was still relatively buggy. I'm also going to go out on a limp here and ask if you have any idea how I could achieve a cover flow view effect with my scroller. This isn't something I necessarily need to do but thought would be kind of cool.

Thanks! – Olshansk Aug 7 '11 at 16:19 If I want to add buttons to the scroll view, meaning I'll add UIButtons to the extended area container in the same locations as the pictures, how would I return the correct button to the receiver when it is pressed? – Olshansk Aug 8 '11 at 18:50 1 with the UIButtons, you might try returning self subviews objectAtIndex:0 hitTest:point withEvent:event instead.

Haven't tried that, but that may be an even better solution. Delegate authority to the scrollview. – picciano Aug 9 '11 at 16:08.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions