使用工作代码更新:除了让按钮滚出页面之外,它们不可见
我知道您说过您查看了滚动视图代表,但这就是您解决此问题的方法。在查看 Pulse 时,唯一棘手的动作是向下滚动时,即看起来像 UIToolbars 的东西消失的时候。您需要拥有的最重要的东西是从 iPhone 可见屏幕底部和顶部的 UIView 继承的任何东西,因此当用户向下或向上滚动时,contentoffset 具有值。
其他每一个动作都会导致它们出现,所以 Pulse 可能做了类似的事情。
#import <UIKit/UIKit.h>
@interface C1ViewController : UIViewController
{
CGPoint _y;
}
@property (weak, nonatomic) IBOutlet UIScrollView *scroller;
@property (weak, nonatomic) IBOutlet UIToolbar *toolbar;
@end
#import "C1ViewController.h"
@interface C1ViewController ()
@end
@implementation C1ViewController
@synthesize scroller = _scroller;
@synthesize toolbar = _toolbar;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.scroller.contentSize = CGSizeMake(self.scroller.frame.size.width, self.scroller.frame.size.height + 100);
self.toolbar.hidden = TRUE;
_y = [self.scroller contentOffset];
}
// this method is getting deprecated, so don't worry about it to much
// but don't forget to dealloc...which I did not include.
- (void)viewDidUnload
{
[self setScroller:nil];
[self setToolbar:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(@"content offset %f", self.scroller.contentOffset);
if (_y.y < [self.scroller contentOffset].y){
self.toolbar.hidden = TRUE;
}
else {
self.toolbar.hidden = FALSE;
}
}
@end
我的视图层次结构在 Interface Builder 中的样子