I am looking for a way to implement a tick noise that plays every time a cell passes a specific point on the screen (the center).
I have been pouring over the web but cant figure out where to start? Any direction would be great (not looking for someone to solve it for me, just some insight or advice)
Thanks!
UPDATE:
Here is the code I have implemented using your method, but it doesn’t work properly. It never seems to call the “Tick” nslog which means something in the parameters is incorrect. My tableview cells are 100 pixels tall. Any advice?
- (void) scrollViewDidScroll:(UIScrollView *)scrollView {
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
self.myTimer = [NSTimer scheduledTimerWithTimeInterval:1/30.0 target:self selector:@selector(checkTableViewScrollPosition) userInfo:nil repeats:YES];
}
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
if (self.myTimer)
[self.myTimer invalidate];
self.myTimer = nil;
}
int currentContentOffset = 0;
int tableviewCellHeight = 100;
int thresholdValue = 50;
- (void) checkTableViewScrollPosition {
int contentOffsetValue = _contentTableView.contentOffset.y;
NSLog(@"%d", contentOffsetValue);
if ((contentOffsetValue + tableviewCellHeight / 2) % tableviewCellHeight <= thresholdValue && currentContentOffset != contentOffsetValue ) {
NSLog(@"Tick!");
NSLog(@"%d", contentOffsetValue);
currentContentOffset = _contentTableView.contentOffset.y;
}
}
Start by adding a property to your view controller to store the index path of the cell at the center of the table:
Then, make sure that your view controller adopts the
UIScrollViewDelegateprotocol, and that your tableView is accessible via the self.tableview property (or change the code below to the appropriate property for the tableView).Then, implement the following method from the
UIScrollViewDelegate: