Добавление тени в UITableView не работает должным образом - PullRequest
0 голосов
/ 01 февраля 2012

Я создал пример приложения для добавления тени в UITableView.Когда вы нажимаете правую кнопку навигации, тень добавляется в таблицу.Проблема в том, что тень добавляется только к той части таблицы, которая видна на экране.Если я попытаюсь прокрутить вверх (и уйти со стола) или прокрутить вниз и увидеть ячейку, тень не будет видна.Как я могу установить тень на всю высоту стола?Если возможно, у меня будет тень также, если я прокручиваю вверх и ухожу со стола (для эффекта отскока).Я прикрепляю два скриншота и код.

На первом скриншоте я прокручиваю вниз, чтобы увидеть ячейку других, во втором прокручиваю вверх для запуска эффекта отскока UITableView по умолчанию.

enter image description hereenter image description here

Вот код:

- (void)printIt:(id)sender
{
    [self.tableView.layer setShadowColor:[[UIColor orangeColor] CGColor]];
    [self.tableView.layer setShadowOffset:CGSizeMake(0, 0)];
    [self.tableView.layer setShadowRadius:15.0];
    [self.tableView.layer setShadowOpacity:0.8];
    [self.tableView.layer setMasksToBounds:NO];
    self.tableView.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.tableView.layer.bounds].CGPath;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIBarButtonItem *testButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(printIt:)];
    self.navigationItem.rightBarButtonItem = testButton;
    [testButton release];
}

#pragma mark UITableView methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
    }

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 105;
}

1 Ответ

5 голосов
/ 01 февраля 2012

Самый простой способ справиться с этим - встроить табличное представление в UIView и установить тень на UIView.

...