Zeropointer
Zeropointer

Reputation: 510

UIScrollView clipsToBounds issue

Hello I have a problem with UIScrollView and I hope someone can help me.

I have a UIView with 700x580 pixel in the center of that view I add a UIScrollview with 350x580 pixel. In this scrollView I add 10 subViews next to each other then I set the property clipsToBounds on the scrollview to NO that I can see the subViews of the scrollView witch was not in the scrollView. Now my problem the subviews of the scrollView was also show at the outside of the UIView. Is there any why to disable that?

Here is a sample code of my problem

UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 700, 580)];
CGFloat viewDisdance = 50;
UIScrollView *theScrollView = [[UIScrollView alloc] 
                               initWithFrame:CGRectMake((myView.frame.size.width-350)/2, // X
                                                        0,                               // Y
                                                        350+viewDisdance,                // with
                                                        580)];                           // height

theScrollView.backgroundColor = [UIColor blueColor];
theScrollView.clipsToBounds = NO;
theScrollView.pagingEnabled = YES;
[myView addSubview:theScrollView];

CGFloat offset = 0.0;
for (NSInteger i = 0; i<10; i++) {
    UIView *aSubView = [[UIView alloc] initWithFrame:CGRectMake(offset, 0, 350, 580)];
    aSubView.backgroundColor = [self randomColor];   //a method that givs me a random color back
    offset += aSubView.frame.size.width;
    offset += viewDisdance;
    [theScrollView addSubview:aSubView];
}

[window addSubview:myView];

Here is a screen from the result of this code sample

Image http://img18.imageshack.us/i/bildschirmfoto20110104u.png/

the red area is myView

the blue area is theScrollView

and the other color areas are the subViews of theScrollView

Upvotes: 0

Views: 4913

Answers (1)

Altealice
Altealice

Reputation: 3572

Can you try myView.clipsToBounds = YES;?

Upvotes: 4

Related Questions