先說一下思路,再上代碼吧
1.這裏主要的難題就是座標的計算,因爲一個是tableView.supperView的座標(購物車圖標),還有一個就是cell中的起始圖標,
思路:我的思路就是在
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
此方法中向cell傳入購物車的view,這樣就能在cell中計算座標了,具體的計算
- (void)starAnimation { //獲取cell的tableview UITableView *tableView = (UITableView *)self.superview.superview; CGRect addFrame = self.addImage.frame; CGPoint layerPoint = CGPointMake(self.frame.origin.x+addFrame.origin.x, self.frame.origin.y-tableView.contentOffset.y+addFrame.origin.y+20); //獲取需要創建的layer的frame CGRect layerFrame = CGRectMake(layerPoint.x, layerPoint.y, addFrame.size.width, addFrame.size.height); LIUCircleLayer *layer = [LIUCircleLayer layoutWithFrame:layerFrame]; [self.willGoView.superview.layer insertSublayer:layer above:tableView.layer]; //創建一個隊列結構來存儲創建的layer,以便結束之後移除 [self.queue addValue:layer]; [layer addAnimation:[self getAnimationWithStartPoint:CGPointMake(CGRectGetMidX(layerFrame), CGRectGetMidY(layer.frame))] forKey:nil]; }
//我覺得這個就是本次中的難點了
好了 具體完整的代碼見github