D
D
deleted-mezhevikin2014-03-21 18:51:32
Cocoa
deleted-mezhevikin, 2014-03-21 18:51:32

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?
thumb.png

@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];
}

rghost.ru/53236356 - full code for this example

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
K
KiriKiri, 2014-03-21
@KiriKiri

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.

D
Denis Morozov, 2014-03-21
@morozovdenis

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.         |
|----------------------------|

for TableView write autoresizingmask = (UIAutoresizingMaskFlixableHeight | UIAutoresizingMaskFlixableWidth) which corresponds to placing all red markers in IB
for ToolBarView write autoresizingmask = (UIAutoresizingMaskFlixableWidth | UIAutoresizingMaskFlixableTopMargin) which corresponds to setting the following markers in IB: left, right, bottom and horizontal right-left arrow

Similar questions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question