用新的缩放路径替换UIBezierPath

时间:2014-12-01 20:53:02

标签: ios uitableview uibezierpath

我有一个UITableViewCell,其中包含一个跨越单元格的UIBezierPath。当我的tableview进入编辑模式时,当单元格移位时,路径右端的一部分会离开屏幕。我的解决方案是在进入编辑模式时缩小路径,然后在退出编辑模式时将其缩放回原始大小。我尝试了这个,然后出现了新的缩小路径,但原始更宽的路径仍然可见。基本上,新的缩小路径是在原始较宽的路径上绘制的。如何在两个路径之间切换以使一个路径消失而另一个路径可见。

- (void)didTransitionToState:(UITableViewCellStateMask)state
{
    [super didTransitionToState:state];


    if (state == UITableViewCellStateShowingEditControlMask)
    {
        CGRect newFrame = CGRectMake(self.waveView.frame.origin.x, self.waveView.frame.origin.y, self.waveView.frame.size.width -100, self.waveView.frame.size.height);

        //Using +100/-100 for testing

        CGFloat scaleFactor = (self.waveView.frame.size.width-100)/self.waveView.frame.size.width;

        self.waveView.frame = newFrame;

        CGAffineTransform transform = CGAffineTransformScale(self.waveView.transform,
                                                         scaleFactor,
                                                         1);

        [self.waveView.path applyTransform:transform];

    }
    else if (state ==UITableViewCellStateDefaultMask)
    {

    // normal mode : back to normal

        CGRect originalFrame = CGRectMake(self.waveView.frame.origin.x, self.waveView.frame.origin.y, self.waveView.frame.size.width +100, self.waveView.frame.size.height);

        CGFloat scaleFactor = (self.waveView.frame.size.width + 100)/self.waveView.frame.size.width;

        self.waveView.frame = originalFrame;

        CGAffineTransform transform = CGAffineTransformScale(self.waveView.transform,
                                                         scaleFactor,
                                                         1);

        [self.waveView.path applyTransform:transform];



    }

}

waveView是UIView的子类,包含以下内容:

@property (nonatomic, strong) CAShapeLayer* blueWave;

-(void) layoutSubviews
{
    [super layoutSubviews];
    self.blueWave = [self createShapeLayer];
    [self.layer addSublayer:self.blueWave];
    [self render];
}

- (void)render 
{
    self.blueWave.path = self.path.CGPath;
}

- (CAShapeLayer *) createShapeLayer 
{
    CAShapeLayer* layer = [[CAShapeLayer alloc] init];
    layer.lineWidth = 2;
    layer.fillColor = nil;

    return layer;
}

cellForRowAtIndex我执行以下操作

cell.waveView.path = [NSKeyedUnarchiver unarchiveObjectWithData:pathData];

0 个答案:

没有答案