30 , tableViewDelegate
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
self.myTickTimer = [NSTimer scheduledTimerWithTimeInterval:1/30.0 target:self selector:@selector(checkTableViewScrollPosition) userInfo:nil repeats:YES];
}
tableViewDidBeginScroller, , .
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
if (myTickTimer)
[myTickTimer invalidate];
self.myTickTimer = nil;
}
tableview.contentOffset , , ...
- (void) checkTableViewScrollPosition
{
NSLog(@"tableview.contentOffset = %@", tableview.contentOffset);
}
Now you have a content offset that assigns the correct numbers .... execute a module on contentOffset based on the height of the tableview cell and you can play the sound whenever it changes .... Remember the content offset will go from 0 - tableViewCellHeight * numberOfCells + headerHeight + footerHeight ... here is the finished method:
int currentContentOffset = 0;
int tableviewCellHeight = 44;
int thresholdValue = 5;
void checkTableViewScrollPosition
{
NSLog(@"tableview.contentOffset = %@", tableview.contentOffset);
if ((tableview.contentOffset+tableviewCellHeight/2.0) % tableviewCellHeight <= threshHoldValue &&
currentContentOffset != tableview.contentOffset)
NSLog(@"Tink");
[[NSSound soundNamed:@"Tink"] play];
currentContentOffset = tableview.contentOffset;
}
source
share