我用两个按钮制作了一个.xib文件,并将其附加到inputAccessoryView上。我使用scrollView使本节可滚动,但我必须使用按钮(箭头)添加其他功能。点击前箭头,它应该走到末端,后箭头将采取的原始位置。


我在UI中创建了完整的ScrollView,没有任何代码。它工作得很好,这些按钮就在这个视图之上,我正在考虑使用这些按钮的IBAction并更改ContentOffSet。我正在努力执行。我会感谢你给我一些建议的。
用于实现的类:
#import "KCSearchInputAccessoryView.h"
@implementation KCSearchInputAccessoryView
+ (KCSearchInputAccessoryView *)viewFromNib {
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
return [[bundle loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil] lastObject];
}
- (IBAction)backBtnTapped:(id)sender {
}
- (IBAction)forwardBtnTapped:(id)sender {
}
@end发布于 2017-03-01 20:17:04
你可以通过改变ContentOffset来做但是..。
假设您有对按钮的引用,更好的方法可能是使用func scrollRectToVisible(_ rect: CGRect, animated: Bool)
IBAction func rightButton(sender: AnyObject) {
self.theScrollView.scrollRectToVisible(postsButton.frame, animated: true)
}
IBAction func leftButton(sender: AnyObject) {
self.theScrollView.scrollRectToVisible(chatsButton.frame, animated: true)
}这也会“滑动”按钮的横穿。
编辑:习惯了使用Swift的人..。
目标-C版本..。另外,不要使用单独的Button框架,只需在滚动视图内容的开头或结尾创建rect:
- (IBAction)backBtnTapped:(id)sender {
CGRect r = CGRectMake(0.0, 0.0, 1.0, 1.0);
[_theScrollView scrollRectToVisible:r animated:YES];
}
- (IBAction)forwardBtnTapped:(id)sender {
CGRect r = CGRectMake(_theScrollView.contentSize.width - 1, 0.0, 1.0, 1.0);
[_theScrollView scrollRectToVisible:r animated:YES];
}https://stackoverflow.com/questions/42540962
复制相似问题