ho sotto lo schermo:multiplo di UIView con UIBezierPath
Quando clicco Get More Button, si aggiungerà nuovo pulsante arrotondato. Ho aggiunto Pan Gesture sullo UIView
in cui sono stati aggiunti tutti i pulsanti arrotondati, che quindi estraggono uno UIBezierPath
solo dal pulsante Arrotondato. Fino a questo punto, tutto funziona.
Ora, voglio il seguente:
- ho genitore
UIView
chiamato playGroundView, che contiene tutte pulsante arrotondato. Questo disegnerà un percorso Bezier per tutti quei pulsanti. - Una volta disegnato il tracciato di Bezier per tutti i pulsanti, faccio clic su Sposta pulsante per animare tutti i pulsanti arrotondati contemporaneamente.
- Una volta che tutto il pulsante si sposta sull'estremità del percorso di Bézier, posso quindi disegnare nuovamente il percorso di Bezier (aggiungere più passaggi per il pulsante arrotondato) allo stesso percorso per lo stesso pulsante.
- Dopo questo, il pulsante Spostamento finale si animerà interamente per lo stesso pulsante in una sola volta.
fare riferimento al codice di sotto per parco giochi UIView sottoclasse:
@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
non sono ancora in grado di gestire tutto lo stato pulsante arrotondato. Fammi sapere il modo migliore per gestire tutto il passaggio di Button arrotondato durante lo spostamento.
ho fatto riferimento a: http://nachbaur.com/blog/core-animation-part-4
Il mio codice demo completo è disponibile all'indirizzo: https://www.dropbox.com/s/f0ri0bff8ioxtpz/FreeHandDrawingDemo%202.zip?dl=0
Ciao, non voglio ricevere il callback per il completamento dell'animazione. Il mio requisito è che, voglio spostare tutti i RoundButton contemporaneamente con movimento relativo. Dì se il mio primo percorso del pulsante è 1 cm e il percorso del Secondo pulsante è 2 cm, quindi il primo pulsante dovrebbe raggiungere il primo e il secondo pulsante dovrebbe richiedere il doppio tempo del primo pulsante. Questa animazione dovrebbe essere simultanea. – DShah
Il mio male, non ti ho capito affatto :) Ho un'idea su come farlo, sto modificando la mia risposta in questo momento. – Bartserk