【发布时间】:2015-04-06 10:19:10
【问题描述】:
我有以下屏幕:
当我点击获取更多按钮时,它会添加新的圆形按钮。我在UIView 上添加了平移手势,其中添加了所有圆形按钮,然后将仅从圆形按钮绘制UIBezierPath。到目前为止,一切正常。
现在,我想要以下内容:
- 我有一个名为 playGroundView 的父
UIView,它包含所有圆形按钮。这将为所有这些按钮绘制一个贝塞尔路径。 - 为所有按钮绘制 Bezier 路径后,我单击“移动按钮”立即为所有圆形按钮设置动画。
- 一旦所有 Button 移动到 Bezier Path 的终点,我就可以再次绘制 Bezier Path(为 Rounded Button 添加更多步骤)连接到相同按钮的相同路径。
- 此后,Final Move 按钮将立即为同一个按钮设置动画。
PlayGround 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
我仍然无法管理所有圆形按钮状态。告诉我在移动时管理圆形按钮所有步骤的最佳方法。
我参考过:http://nachbaur.com/blog/core-animation-part-4
我的完整演示代码位于:https://www.dropbox.com/s/f0ri0bff8ioxtpz/FreeHandDrawingDemo%202.zip?dl=0
【问题讨论】:
标签: ios objective-c animation uiview calayer