user2947788
user2947788

Reputation: 37

UIScrollView strange behavior on device

I have implemented a 'UIScrollView' in my application, like this :

scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(59.0, 116, 180, 145)];
[scroller setBackgroundColor:[UIColor clearColor]];
[scroller setPagingEnabled:NO];
[scroller setScrollEnabled:NO];
[scroller setDelegate:self];
if (![scroller isDescendantOfView:MyUIView])
{
    [MyUIView addSubview:scroller];
}

To scroll, I add a 'UIButton' which do :

Y = Y + 200;
[scroller setContentOffset:CGPointMake(Y, 0) animated:YES];
NSLog(@"Scroll : %f", scroller.contentOffset.x);

On the 'simulator', this works ! But on the device, the scroller.contentoffset.x gives me some random values and so move my content really strangely… The simulator and my device are in 'release' mode

I don't really understand why this doesn't works because in a precedent app, it was working perfectly.

Thanks for your help !

EDIT :

When doing :

[scroller setContentOffset:CGPointMake(Y, 0) animated:NO];

it works correctly

When doing :

[scroller setContentOffset:CGPointMake(Y, 0) animated:YES];

it gives me random values, and do some wrong things

Upvotes: 0

Views: 690

Answers (2)

user2947788
user2947788

Reputation: 37

I found a solution, it looks to be a bug. Here is the solution.

[UIView animateWithDuration:.25 animations:^{
self.scrollView.contentOffset = ...;
}];

Upvotes: 0

Sathe_Nagaraja
Sathe_Nagaraja

Reputation: 163

Try Scroll rect to visible method instead

- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated

Pass the rect of your interest. Also make sure that you have set the contentSize of your scrollview.

Upvotes: 1

Related Questions