Spacebar for UIScrollView (iOS 8)
I wanted to create scrollable buttons at the bottom of the screen (like filters in Photos), which is the TOC (table of contents) for many pages. I used to write similar code below (in Objective-C) works great in iOS 7, so not sure if this is my quick conversion or an issue with iOS 8.
tocView = UIScrollView(frame:CGRect(x:0, y:self.view.frame.size.height, width:self.view.frame.size.width, height:thumbHeight))
for i in 0 ..< pages.count {
let image = UIImage(named:pages[i].name)
var button = UIButton.buttonWithType(.Custom) as UIButton
button.setImage(resizeImage(image, size:CGSize(width:thumbWidth, height:thumbHeight)), forState:.Normal)
button.frame = CGRect(x:thumbWidth * CGFloat(i), y:0, width:thumbWidth, height:thumbHeight)
button.addTarget(self, action:"selectPage:", forControlEvents:.TouchUpInside)
button.tag = i
tocView.addSubview(button)
}
Everything works fine - except that scrolling doesn't always work. Half of the time I try to pass it seems like the button below will remove the swipe and the swipe won't. Only when I slipped very quickly can a date happen. I want to be able to detect the correct napkin or tap. Anyone having a similar issue?
source to share
I don't know how to do it in swift , but I had the same problem in objC, so my permission has a subclass of UIScrollView and add this:
- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
{
UITouch *touch = [touches anyObject];
if(touch.phase == UITouchPhaseMoved)
{
return NO;
}
else
{
return [super touchesShouldBegin:touches withEvent:event inContentView:view];
}
}
change
After a couple of tests I found the problem, sometimes the UIButton action is not called ... so I replace the method with touchShouldCancelInContentView and it worked better ... y can try
- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
return YES;
}
source to share