I have a UITableViewController. In the UITableView I have a subview - ImageView. ImageView this is my header of TableView. I want that header (ImageView) is always on top when I scroll.
I have the following code which work on IOS 5, but does not work on IOS 6:
- (Void) scrollViewDidScroll: (UIScrollView *) scrollView {
[ImageView setFrame: CGRectMake (0, self.tableView.contentOffset.y, 320, 100)];
}
So, what should I do to solve this problem on IOS 6?
The header and footer in UITableView and UICollection view are fixed inside there container scrollview. What you need to do is actually place a button outside of your UITableViewController and added after that controller either in Interface builder or when setting up your VC in viewDidload. This will then be above the scroll view. You might want to resize the UITableViewController so that the content doesnt pass under the button.
Related
I'm using Masonry to set the constraints of the subviews.
The view controller is simple.
in viewDidLoad
-(void)viewDidLoad
{
[self.view addSubview: self.tableView];
self.view.backgroundColor = [UIColor whiteColor];
[self.tableView addSubview: self.botBtn];
[self.botBtn makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.tableView.bottom).with.offset(-20);
make.centerX.equalTo(self.tableView);
}];
}
The frame for the table view is CGRectMake(0,0,screen_width,screen_height),
but the button is outside of the screen and just on the top of the tableview.
I set the tableview frame in it's init method.
The button stays in the mid of the view horizontally so the autolayout seems work, but why it is positioned on the top of the tableview instead of staying on the bottom.
Firstly well done for using Masonry :D.
To your question, I don't think you're adding the button in the right way, I'm guessing you want to add a button to bottom of the tableview, so when you scroll to the bottom of the tableview you will see your button? If so, just create a UIView with a button and set the tableview's footer view, i.e. [self.tableView setTableFooterView:newView]; as described in this question, Adding a button at the bottom of a table view
Let me know if this is not what you're actually looking for, good luck.
I created an iPhone app where it came with the UINavigationController and UITableView predefined.
I want to add an UIView on the top of the screen but every time user scrolls tableView, my view also scrolls. Is there anyway to make the view independent from the tableView scroll?
Thanks
Don't use UITableViewController, use UIViewController and add UITableView as a subview
Create your view and set it as table header view of your table view.
UIView *yourView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
[self.tableView setTableHeaderView:yourView];
It will not scroll with tableView but always remain on top of table view.
I am currently trying to remove the top or bottom view from my tableview but the size of the whole tableview isnt just right. Here is what i did so far.
Created a TableviewController inside the Storyboard
Created a Class derived from UITableViewController and set
everything up like delegate etc.
Dragged a view to the top of the tableview inside the Storyboard
Created and connected an outlet named topview for this
In Viewwillappear i will remove that topview dependent of some value so i tried some things
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if(foo){
[self.topView setHidden:YES];
// or
[self.topView removeFromSuperview];
// or
[self.topView setFrame:CGRectMake(0, 0, 0, 0)];
}
}
For example if i remove the view from superview the topview isnt available anymore but there is a big gap on top .. how can i remove this top view from my tableview without having this gap ?
I put some Screenshots to describe my Problem:
If you put it inside the tableview it is probably the tableHeaderView. Try this:
self.tableView.tableHeaderView = nil;
Should remove the view and update the tableview accordingly.
[self.tableview reloadData]
after removing topview or if you're using autolayout then you can use [self.view updateConstraints];
Hi everyone. I dragged a UIScrollView to my storyboard, then I added a UIView on top of that UIScrollView. This UIView loads another subview dynamically depending on what the server throws to this app.
The problem is the UIScrollView is not scrolling the content, even though I made the loaded UIView bigger than the UIScrollView. I'm not invoking [myScroller addSubView:myUiView]. Am I doing it right? Thanks in advance!
For every time you change the content try calling
//removeFromSuperview the UIView was set as content view
self.myScroller.contentSize = self.myUiView.frame.size;
[myScroller addSubView:myUiView];
Don't forget to link both views on Interface Builder
PS: In this apporach the subView must not be inside the scrollView on IB
You must set the content size of the scroll view.
Add this in your view controller.
- (void) viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
myScroller.contentSize = CGSizeMake(CGRectGetMaxX(myUiView.frame), CGRectGetMaxY(myUiView.frame));
}
I have the CNN app on my iPhone.
If you open it will show "top stories", and has always a picture on the top of the table.
When we slide our finger down it expands/zooms the image.
When we slide our finger up to show more rows it does not move the image upwards at the same speed has the table rows instead the table rows move faster than the picture going off the screen.
Do you know how to do this effect?
You need UIImageView to UIScrollView contentInset and set top inset more than zero.
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
UIImage *topImage = [UIImage imageNamed:#"photo"];
topImage.frame = CGRectMake(0, -topImage.frame.size.height, topImage.frame.size.width, topImage.frame.size.height);
[scroll addSubview:topImage];
self.contentInset = UIEdgeInsetsMake(topImage.frame.size.height, 0, 0, 0);
After that set UIScrollView's contentOffset like this
scroll.contentOffset = CGPointMake(0, topImage.frame.size.height);
So you have the UIScrollView with image inside it. Now you just need to add delegate to UIScrollView and wait for - (void)scrollViewDidScroll:(UIScrollView *)scrollView. Resize image and change contentInset right after this method called.
This advice you also can apply to UITableView similar way, or create category on UIScrollView.
I also advice you to read code of this project https://github.com/samvermette/SVPullToRefresh. It's also about UITableView and adding view to it's top side
It seems like a completely custom effect that you will have to implement yourself. To point you in the right direction, I'd first monitor contentOffset changes in the scrollViewDidScroll: messages sent by your myTableView instance, and when the contentOffset.y < 0, change the scale of your imageView via
[myImageView setValue:[NSNumber numberWithFloat:scaleIncrementAmountFloat] forKeyPath:#"transform.scale"];
My guess is that the top cell (or cells) of the tableview are transparent and there is a UIImageView behind the tableview that is resized/moved based on how the table view is scrolled.
Since the table view inherits from UIScrollView, its delegate (UITableViewDelegate) inherits from the UIScrollViewDelegate protocol which is notified when a the user scrolls the scroll view. Implement the - (void)scrollViewDidScroll:(UIScrollView *)scrollView method to receive these notifications and check the contentOffset property on the scroll view.
You may have to implement you own table view controller to build the desired UI in the interface builder.