2013-03-12 68 views
0

這是一個微妙的問題:我有一個帶滑塊和分段控件的自定義tableview單元格。當表格進入編輯模式時,一切看起來都很好,當紅色的刪除按鈕出現時,滑塊和分段控件的寬度會縮小,從而在右側爲刪除按鈕留出空間,並且此縮小會正確動畫。所以一切都很好。當刪除按鈕出現時,在自定義表格視圖單元格中缺少UISlider寬度的動畫

但是,當用戶沒有通過刪除操作並跳出界限時,滑塊會在刪除按鈕動畫輕掃完成之前立即彈回到其全部寬度。然而,分段控制被正確地動畫回到其全部寬度。我沒有自己處理任何動畫。爲什麼滑塊不能動畫?我的設置代碼如下。有任何想法嗎?

請注意,當左側圓形紅色選擇按鈕出現或消失時,所有元素的動畫效果都很好。

如果我不能修復這個問題,我想知道如何從內容推到左邊停止刪除按鈕出現時,但保留選擇按鈕壓痕動畫。

NSArray *itemArray = @[@"1", @"2", @"3", @"4"]; 
self.source = [[[UISegmentedControl alloc] initWithItems:itemArray] autorelease]; 
self.source.frame = CGRectMake(80, 10, cb.size.width - 92, 36); 
self.source.segmentedControlStyle = UISegmentedControlStylePlain; 
self.source.selectedSegmentIndex = 0; 
self.source.autoresizingMask = UIViewAutoresizingFlexibleWidth; 
[self.contentView addSubview:self.source]; 

self.phaseSlider = [[[UISlider alloc] initWithFrame:CGRectMake(80, 50, cb.size.width - 92, 36)] autorelease]; 
self.phaseSlider.continuous = TRUE; 
self.phaseSlider.autoresizingMask = UIViewAutoresizingFlexibleWidth; 
[self.contentView addSubview:self.phaseSlider]; 

回答

0

我發現了這個解決方案。顯然,使用調整大小掩碼時會出現一些問題,以便在刪除按鈕出現時允許滑塊調整大小。相反,我刪除了靈活的寬度調整大小掩碼。我初始化initWithStyle中的控件,但只設置layoutSubViews中的幀。這實際上是設置控制幀的更好方法,因爲單元格的寬度和高度在initWithStyle中實際上並不確定。當您在layoutSubViews中設置框架時,會在刪除按鈕出現和消失動畫期間被調用,並且位置和大小會正確動畫。

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) 
    { 
     // Initialization code 
     NSArray *itemArray = @[@"1", @"2", @"3", @"4"]; 
     self.source = [[[UISegmentedControl alloc] initWithItems:itemArray] autorelease]; 
     self.source.segmentedControlStyle = UISegmentedControlStylePlain; 
     self.source.selectedSegmentIndex = 0; 
     [self.contentView addSubview:self.source]; 

     self.phaseSlider = [[[UISlider alloc] initWithFrame:CGRectZero] autorelease]; 
     self.phaseSlider.continuous = TRUE; 
     [self.contentView addSubview:self.phaseSlider]; 

     self.selectionStyle = UITableViewCellSelectionStyleNone; 
    } 
    return self; 
} 

- (void)layoutSubviews 
{  
    [super layoutSubviews]; 

    float w = self.contentView.bounds.size.width; 

    self.source.frame = CGRectMake(78, 10, w - 92, 36); 
    self.phaseSlider.frame = CGRectMake(78, 50, w - 92, 36); 
} 
+0

你知道你可以接受你自己的解決方案嗎? – 2015-07-03 21:04:06

相關問題