動畫我有以下屏幕:多的UIView與UIBezierPath
當我點擊獲取更多按鈕,它會增加新的圓形按鈕。我在UIView
中添加了Pan Gesture,其中添加了所有的圓形按鈕,然後只會從Rounded Button繪製一個UIBezierPath
。到目前爲止,一切正常。
現在,我想以下幾點:
- 我父
UIView
稱爲playGroundView,它包含了所有圓形按鈕。這將爲所有這些按鈕繪製一條Bezier路徑。 - 一旦爲所有按鈕繪製了貝塞爾路徑,然後單擊移動按鈕一次爲所有圓形按鈕設置動畫效果。
- 有一次,所有的Button都移動到Bezier路徑的終點,然後我可以再次爲同一個按鈕繪製更多的Bezier路徑(爲Rounded Button添加更多步驟)連接到同一路徑。
- 之後,Final Move按鈕將立即爲同一個Button設置動畫。
參考下面的代碼操場UIView子類:
@interface PlayGroundView : UIView
@property (nonatomic, weak) PlayGroundViewController *playViewController;
@end
#import "PlayGroundView.h"
#import "RoundedButton.h"
#import "PlayGroundViewController.h"
@interface PlayGroundView() {
UIBezierPath *path;
BOOL isDrawPointInside;
}
@end
@implementation PlayGroundView
#pragma mark - View Methods -
- (id)initWithCoder:(NSCoder *)aDecoder {
if (self = [super initWithCoder:aDecoder])
[self commonInit];
return self;
}
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame])
[self commonInit];
return self;
}
- (void)drawRect:(CGRect)rect {
[[UIColor redColor] setStroke];
[path stroke];
}
#pragma mark - Action Methods -
- (void)pan:(UIPanGestureRecognizer *)pan {
CGPoint currentPoint = [pan locationInView:self];
// NSLog(@"currentPoint: %@", NSStringFromCGPoint(currentPoint));
if (pan.state == UIGestureRecognizerStateBegan) {
NSMutableArray *buttonAry = [NSMutableArray array];
buttonAry = self.playViewController.rBtnOpponentPlayerList;
[buttonAry addObjectsFromArray:self.playViewController.rBtnPlayerList];
for (int i=0; i<buttonAry.count; i++) {
UIButton *btn = [buttonAry objectAtIndex:i];
CGRect nearByRect = CGRectMake(btn.frame.origin.x - 20, btn.frame.origin.y - 20, btn.frame.size.width + 40, btn.frame.size.height + 40);
if (CGRectContainsPoint(nearByRect, currentPoint)) {
isDrawPointInside = YES;
[path moveToPoint:btn.center];
// NSLog(@"point is inside....");
}
}
}
if (pan.state == UIGestureRecognizerStateChanged) {
if (isDrawPointInside) {
[path addLineToPoint:currentPoint];
[self setNeedsDisplay];
}
}
if (pan.state == UIGestureRecognizerStateEnded) {
isDrawPointInside = NO;
// NSLog(@"pan ended");
}
}
#pragma mark - Helper Methods -
- (void)commonInit {
path = [UIBezierPath bezierPath];
path.lineWidth = 3.0;
// Capture touches
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
pan.maximumNumberOfTouches = pan.minimumNumberOfTouches = 1;
[self addGestureRecognizer:pan];
// Erase with long press
[self addGestureRecognizer:[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(erase)]];
}
- (void)erase {
path = [UIBezierPath bezierPath];
path.lineWidth = 3.0;
[self setNeedsDisplay];
}
@end
我仍然不能夠管理所有圓形按鈕的狀態。讓我知道移動時管理Rounded Button所有步驟的最佳方法。
我都提到:http://nachbaur.com/blog/core-animation-part-4
我的全部演示代碼,請訪問:https://www.dropbox.com/s/f0ri0bff8ioxtpz/FreeHandDrawingDemo%202.zip?dl=0
嗨,我不想回調動畫完成。我的要求是,我想通過相對運動同時移動所有RoundButton。假設我的第一個按鈕路徑是1釐米,第二個按鈕路徑是2釐米,那麼第一個按鈕應該到達第一個按鈕,第二個按鈕應該是第一個按鈕的兩倍。這個動畫應該是同時的。 – DShah 2015-04-16 05:06:12
我的不好,我根本不理解你:)我有一個想法,如何做到這一點,我現在正在編輯我的答案。 – Bartserk 2015-04-16 08:03:37