Answer the question
In order to leave comments, you need to log in
How to solve problems with getting size of UIView when translucent property is disabled (ios7)?
There is a custom view controller with a table. At the bottom, the view is pressed (green on the screen), when the screen is flipped, the resize method is called and redraws the coordinates. With translucent = YES, everything works fine, but if you turn off transparency, then the green view disappears, how to get the correct coordinates? Or only autolaouts only hardcore?
@implementation CustomTableViewController
- (void)viewDidLoad
{
[self.navigationController.navigationBar setTranslucent:NO];
[super viewDidLoad];
[self addTableView];
[self loadData];
[self addToolbar];
}
- (void)addTableView
{
self.tableView = ;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.textLabel.text = [self.data objectAtIndex:indexPath.row];
cell.textLabel.textColor = [UIColor redColor];
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.data.count;
}
- (void)addToolbar
{
self.toolBar = [[UIView alloc] init];
self.toolBar.backgroundColor = [UIColor greenColor];
[self.view addSubview:self.toolBar];
[self resize];
}
- (void)resize
{
float height = 50;
self.toolBar.frame = CGRectMake(
0,
self.view.frame.size.height - height,
self.view.frame.size.width,
height
);
self.tableView.frame = CGRectMake(
0,
0,
self.view.frame.size.width,
self.view.frame.size.height-height
);
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[self resize];
}
Answer the question
In order to leave comments, you need to log in
Alternatively, make your toolbar the footer of the last section of the table, then you won't need any coordinates.
If > iOS 6.1 they say that this can be solved by using autoLayout, but I have never tried it myself.
1. don't use UITableViewController - use UIViewController. From my own experience, I’ll say that it’s better to let another view lie under the table
. 2. The good old autoresizing is still enough for me. something complicated is better to sign with 3 lines of code
|----------------------------|
| |
| |
| |
| tableView |
| |
| |
|----------------------------|
|----------------------------|
| ToolBarView. |
|----------------------------|
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question