0

I have 2 views are connected with NavigationController. Second view is scrollView with page controll. My main view has 1 UIButton. When pressing on it are obtained 3-4 seconds delay. There are 21 views in scrollView. And I have spurts when scrolling between view in scrollView. How can I reduce delay and remove spurts?

My viewDidLoad method:

-(void)viewDidLoad {
self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0.0f, 280.0f, 320.0f, 20.0f)];
[self.view addSubview:self.pageControl];

self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, 30.0f, 480.0f, 250.0f)];
[self.view addSubview:self.scrollView];

pageControlBeingUsed = NO;

NSInteger firstNumber = 1;
for (NSUInteger i = 0; i < 20; i++) {
    BIDExercisePrototype *view = [[BIDExercisePrototype alloc] initWithNumber:firstNumber];
    [self.viewsArray addObject:view];
    firstNumber += 50;
}


for (NSUInteger i = 0; i < 20; i++) {
    UIViewController *someController = [[UIViewController alloc] init];
    someController = [self.viewsArray objectAtIndex:i];
    someController.view.frame = CGRectMake(480.0f*i, 0.0f, 480.0f, 280.0f);
    [self.scrollView addSubview:someController.view];
}
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * self.viewsArray.count, self.scrollView.frame.size.height);
self.pageControl.backgroundColor = [UIColor clearColor];
self.pageControl.currentPage = 0;
self.pageControl.numberOfPages = self.viewsArray.count;
self.scrollView.showsVerticalScrollIndicator = NO;
self.scrollView.showsHorizontalScrollIndicator = NO;
self.scrollView.pagingEnabled = YES;
self.scrollView.delegate = self;
[self.pageControl addTarget:self action:@selector(changePage) forControlEvents:UIControlEventValueChanged];
}

- (void)scrollViewDidScroll:(UIScrollView *)sender {
if (!pageControlBeingUsed) {
    CGFloat pageWidth = self.scrollView.frame.size.width;
    int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    self.pageControl.currentPage = page;
}
    }

    - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
pageControlBeingUsed = NO;
    }

    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
pageControlBeingUsed = NO;
    }

    - (void)changePage {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
[self.scrollView scrollRectToVisible:frame animated:YES];

pageControlBeingUsed = YES;
    }
RomanHouse
  • 2,552
  • 3
  • 23
  • 44

2 Answers2

1

I think you should be able to follow the same practice for improving UITableView's scroll performance.

Do your drawing manually and have only one view in each cell.

Check out the following SO post which discusses multiple ways to improve scrolling performance by rendering your cells in specific ways.

Tricks for improving iPhone UITableView scrolling performance?

Community
  • 1
  • 1
Chris Wagner
  • 20,773
  • 8
  • 74
  • 95
  • But I'm not used UITableView. Only scrollView with UIView's inside – RomanHouse Jun 18 '12 at 22:46
  • I realize you aren't but views are views, UITableView inherits from UIScrollView. UITableViewCell is a UIView. The methods described in that post improve performance by reducing the number of subviews required to render and mashing them all into one so that while scrolling, the UIScrollView does not need to render all the individual subviews. I think the concept would would perfectly fine on a UIScrollView with UIViews placed on it. – Chris Wagner Jun 19 '12 at 22:26
1

May I suggest you forget about recoding the wheel (so to speak) and use existing projects that have already solved the problems

Paul de Lange
  • 10,613
  • 10
  • 41
  • 56