Reputation: 3212
I'm a newbie to iOS and i'm trying to develop an application based on news.
In my application , I have a Root View Controller which is a Table View Controller to display news' title and news' images. Well, when users click on the table cell ,there is another View Controller to be displayed which is more detailed and scrollable.
In the View Controller,users can share the news in Facebook and Twitter so that i have two buttons at least. What i want to do is displaying these two button when users scroll up. When users scroll down,i want to make them disappear. There is something like in Pulse News. I have already looked Scroll View delegate methods,but i didn't make it work. How can i accomplish what i want to do ?
Thanks in advance.
Upvotes: 1
Views: 1194
Reputation: 1740
UPDATED WITH WORKING CODE: Outside of having the buttons scroll off the page so they are not visible
I know you said you looked at the scrollview delegates but this how you would solve this issue. In looking at Pulse the only tricky action is when you scroll down, which is when what look like UIToolbars fade away. The most important thing you need to have is anything that inherits from UIView at the very bottom and top of the visible screen of iPhone so when the user scrolls down or up the contentoffset has a value.
Every other actions cause them to appear sooo Pulse probably did something like this.
#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
What my view hierarchy looks like in Interface Builder
Upvotes: 0
Reputation: 47
Create button at the position where you want in scroll according to scroll position.
scroll.frame.origin.x;
scroll.frame.origin.y;
scroll.frame.size.height;
scroll.frame.size.width;
Now you can put the button as you wish on scroll view:
button = [[UIButton alloc] initWithFrame:CGRectMake(x,y,x1,y1);
Upvotes: 1