Ich benutze dies für die Skalierung und eine UIView in meiner app ziehen.
1) Zunächst müssen Sie die folgende in der Implementierung und verbinden die Auslässe auf Ihre Ansichten hinzuzufügen in Ihrem Storyboard
#import <QuartzCore/QuartzCore.h>
@interface yourclass() {
BOOL isDragging;
}
@property (weak, nonatomic) IBOutlet UIImageView *outletMainView; // View that contains the view we want to drag
@property (weak, nonatomic) IBOutlet UIImageView *outletRedDot; // The view we want to drag in the main view
Wenn die Berührung beginnt ich die Ansicht, die ein bisschen skaliert, wenn der Benutzer die spezifische Sicht berührt , hier red dot
// ANIMATE RED DOT WHEN START DRAGING IT
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:self.outletMainView];
CGRect redDotRect = [self.outletRedDot frame];
if (CGRectContainsPoint(redDotRect, touchLocation)) {
isDragging = YES;
NSLog(@"Red Dot tapped!");
[UIView animateWithDuration:0.2
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
self.outletRedDot.transform = CGAffineTransformMakeScale(1.75, 1.75);
}
completion:^(BOOL finished) {
}];
} else {
return;
}
}
2) Dann habe ich die Ansicht ist der Punkt des Fingers Punkt
// ANIMATE AND MOVE RED DOT WHEN WE DRAG IT
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:self.outletMainView];
if (isDragging) {
[UIView animateWithDuration:0.0f
delay:0.0f
options:(UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseInOut)
animations:^{
self.outletRedDot.center = touchLocation;
NSLog(@"X: %0.2f Y: %0.2f",touchLocation.x-redDotStartCenter.x, redDotStartCenter.y-touchLocation.y);
}
completion:NULL];
}
}
0 folgen Schließlich
3), wenn das Ziehen der Ansicht, endet in seine ursprüngliche Skala zurückgesetzt
// RESET RED DOT WHEN WE STOP DRAGGING
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:self.outletMainView];
CGRect redDotRect = [self.outletRedDot frame];
if (CGRectContainsPoint(redDotRect, touchLocation)) {
[UIView animateWithDuration:0.1
delay:0.0
options:0
animations:^{
self.outletRedDot.transform = CGAffineTransformMakeScale(1.0, 1.0);
}
completion:^(BOOL finished) {
}];
}
isDragging = NO;
}
Danke für die Antwort, ich werde dieses Projekt untersuche ich das Ergebnis getestet und ich denke, es kann mir hilft viel, danke. – rokimoki