나는 다음과 같은 방식으로있는 UIImageView를 회전 할 : 나는 이미지 뷰를 잡고 왼쪽으로 손가락을 이동하면 다음 이미지 뷰가 오른쪽으로 회전해야 다음 iPhone : UIImageview를 왼쪽 또는 오른쪽으로 회전하는 방법?
링크 Balance (그리고 그 반대의 경우도 마찬가지입니다.)답변
나는 작년과 함께 사기 친다. 그것은 내가 생각했던 것보다 더 복잡한 것으로 판명되었습니다. IIRC,이 작은 학급이 당신이 원하는대로했습니다. 이미지를 표시하고 클릭 및 드래그에 응답하는 UIButtonSubclass입니다. 이것은 스크래치 코드 일뿐입니다. 메모리 관리, 정리 등을하지 않습니다.
#import <UIKit/UIKit.h>
#import "BackgroundImageButton.h"
#import "WiggleImageView.h"
@interface StickerButton : UIButton {
//ivars used to control selection animaiton
CGAffineTransform startTransform;
BOOL currentlyAnimating;
BOOL shouldAnimate;
//ivars to handle touches and control events
BOOL wasDrag;
BOOL wasTouchDown;
WiggleImageView * imgView;
}
//ivars used to control selection animaiton
@property CGAffineTransform startTransform;
@property(nonatomic, retain) WiggleImageView *imgView;
@property BOOL currentlyAnimating;
@property BOOL shouldAnimate;
//ivars to handle touches and control events
@property BOOL wasDrag;
@property BOOL wasTouchDown;
#pragma mark Initialization
-(id) initWithImage:(UIImage *)anImage atCenterPoint:(CGPoint) centerPoint;
#pragma mark Selection Animation Methods
-(void) animateSelection;
-(void) animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context;
#pragma mark Self Touch Methods //not as dirty as it sounds.
-(void) touchDragSelf:(id)sender withEvent:(UIEvent *) theEvent;
-(void) touchDownSelf:(id)sender withEvent:(UIEvent *) theEvent;
-(void) touchUpSelf:(id)sender withEvent:(UIEvent *) theEvent;
#pragma mark Graphic Edit Methods
-(void) rotateRight;
-(void) rotateLeft;
-(void) scaleUp;
-(void) scaleDown;
-(void) select;
-(void) deselect;
-(void) translateMoveByX:(CGFloat) dx andY:(CGFloat) dy; //used by self to account for translated coordinates
-(void) frameMoveByX:(CGFloat) dx andY:(CGFloat) dy; //used by external to move frame in superview
@end
#import "StickerButton.h"
@implementation StickerButton
@synthesize startTransform;
@synthesize currentlyAnimating;
@synthesize shouldAnimate;
@synthesize wasDrag;
@synthesize wasTouchDown;
@synthesize imgView;
#pragma mark Initialization
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
startTransform=self.transform;
currentlyAnimating=NO;
shouldAnimate=NO;
wasDrag=NO;
wasTouchDown=NO;
self.adjustsImageWhenDisabled=NO;
self.adjustsImageWhenHighlighted=NO;
self.showsTouchWhenHighlighted=NO;
[self addTarget:self action:@selector(touchDownSelf:withEvent:) forControlEvents:UIControlEventTouchDown];
[self addTarget:self action:@selector(touchDragSelf:withEvent:) forControlEvents:UIControlEventTouchDragInside];
[self addTarget:self action:@selector(touchUpSelf:withEvent:) forControlEvents:UIControlEventTouchUpInside];
}
return self;
}
-(id) initWithImage:(UIImage *)anImage atCenterPoint:(CGPoint) centerPoint{
CGFloat xOrigin,yOrigin;
xOrigin=centerPoint.x-(anImage.size.width/2);
yOrigin=centerPoint.y-(anImage.size.height/2);
[self initWithFrame:CGRectMake(xOrigin, yOrigin, anImage.size.width, anImage.size.height)];
WiggleImageView *w=[[WiggleImageView alloc] initWithFrame:self.bounds];
imgView=w;
imgView.image=anImage;
[self addSubview:imgView];
return self;
}//------------------------------------initWithImage:atCenterPoint:------------------------------------
#pragma mark Selection Animation Methods
-(void) animateSelectedThrob{
if (!currentlyAnimating) {
NSLog(@"animating");
currentlyAnimating=YES;
//startTransform=self.transform; //this has to be saved to prevent some kind of rounding error from gradually rotating the view
[UIView beginAnimations:@"selectionAnimation" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.1];
[UIView setAnimationRepeatCount:1];
[UIView setAnimationRepeatAutoreverses:YES];
self.transform=CGAffineTransformScale(self.transform, 1.1, 1.1);
[UIView commitAnimations];
}
}//-------------------------------------(void) animateSelectedThrob------------------------------------
-(void) animateSelection{
if (!currentlyAnimating) {
//NSLog(@"animating");
currentlyAnimating=YES;
startTransform=self.transform; //this has to be saved to prevent some kind of rounding error from gradually rotating the view
[UIView beginAnimations:@"selectionAnimation" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.1];
[UIView setAnimationRepeatCount:2];
[UIView setAnimationRepeatAutoreverses:YES];
self.transform=CGAffineTransformRotate(self.transform, (2 * M_PI/180));
[UIView commitAnimations];
}
}//-------------------------------------(void) animateSelection------------------------------------
-(void) animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{
self.transform=startTransform;
currentlyAnimating=NO;
if (shouldAnimate) {
[self animateSelection];
}
}//------------------------------------animationDidStop:finished:context:------------------------------------
#pragma mark Self Touch Methods
-(void) touchDownSelf:(id)sender withEvent:(UIEvent *) theEvent{
NSLog(@"touchDownSelf");
wasTouchDown=YES;
shouldAnimate=NO;
}//------------------------------------touchDownSelf:withEvent:------------------------------------
-(void) touchDragSelf:(id)sender withEvent:(UIEvent *) theEvent{
NSLog(@"touchDragSelf");
if ([[theEvent touchesForView:self] count]==1) {
UITouch *t=[[theEvent touchesForView:self] anyObject];
CGPoint l,p;
l=[t locationInView:self];
p=[t previousLocationInView:self];
[self translateMoveByX:(l.x-p.x) andY:(l.y-p.y)];
wasDrag=YES;
}
}//------------------------------------touchDragSelf:withEvent:------------------------------------
-(void) touchUpSelf:(id)sender withEvent:(UIEvent *) theEvent{
NSLog(@"touchUpSelf");
// if (!wasDrag && wasTouchDown) {
// [self select];
// }
if (wasTouchDown) {
[self select];
}
wasDrag=NO;
wasTouchDown=NO;
}//------------------------------------touchUpSelf:withEvent:------------------------------------
#pragma mark Graphic Edit Methods
-(void) rotateRight{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.1];
[UIView setAnimationBeginsFromCurrentState:YES];
self.transform=CGAffineTransformRotate(self.transform, (M_PI/180));
[UIView commitAnimations];
}//-------------------------------------(void) rotateRight------------------------------------
-(void) rotateLeft{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.1];
[UIView setAnimationBeginsFromCurrentState:YES];
self.transform=CGAffineTransformRotate(self.transform, (-1*M_PI/180));
[UIView commitAnimations];
}//-------------------------------------(void) rotateLeft------------------------------------
-(void) scaleUp{
//todo add variable to track total scale so it doesn't get to big and cause problems
shouldAnimate=NO;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.1];
[UIView setAnimationBeginsFromCurrentState:YES];
self.transform=CGAffineTransformScale(self.transform, 1.1, 1.1);
[UIView commitAnimations];
startTransform=self.transform;
}//-------------------------------------(void) scaleUp------------------------------------
-(void) scaleDown{
//todo add variable to track total scale so it doesn't get to small and cause problems
shouldAnimate=NO;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.1];
[UIView setAnimationBeginsFromCurrentState:YES];
self.transform=CGAffineTransformScale(self.transform, 0.9, 0.9);
[UIView commitAnimations];
startTransform=self.transform;
}//-------------------------------------(void) scaleDown------------------------------------
-(void) select{
[self animateSelectedThrob];
imgView.shouldWiggle=YES;
}
//-------------------------------------(void) select------------------------------------
-(void) deselect{
imgView.shouldWiggle=NO;
}
-(void) translateMoveByX:(CGFloat) dx andY:(CGFloat) dy{ //necessary for all points that orignate within the transformed view
NSLog(@"dx=%f,dy=%f",dx,dy);
shouldAnimate=NO;
self.transform=CGAffineTransformTranslate(self.transform, dx,dy);
startTransform=self.transform;
}//------------------------------------translateMoveByX:andY:------------------------------------
-(void) frameMoveByX:(CGFloat) dx andY:(CGFloat) dy{ //necessary for all points that originate outside the transformed view
self.frame=CGRectMake(self.frame.origin.x+dx, self.frame.origin.y+dy, self.frame.size.width, self.frame.size.height);
}//------------------------------------frameMoveByX:andY:------------------------------------
- (void)drawRect:(CGRect)rect {
// Drawing code
}
- (void)dealloc {
[super dealloc];
}
@end
컨트롤러에 드래그 시작을 추적 할 수있는 ivar가있을 수 있습니다. '터치 다운'이벤트가 발생하면 시작 지점을 저장하십시오. '터치 이동'이벤트가 발생하면 현재 지점에서 저장된 지점까지의 거리를 계산하십시오. 둘 사이의 유클리드 거리 (Euclidean distance)는 회전 (회전 방향을 알려주는 부호)을 줄 수 있습니다. 회전을 적절하게 조절합니다 (예 :보기 너비의 절반이 180 °와 같습니다). 이미지의 변환 회전을 설정합니다.
샘플을 게시 할 수 있습니까? –
여기에는 기존 코드가 없습니다. 방금 문제를 어떻게 해결할 지 설명했습니다. 위의 설명을 너무 어려움없이 코드로 변환 할 수 있어야합니다! 재밌게 지내세요 ... – gavinb
괜찮아요. 반쯤 있지만 문제가 있습니다. ImageView는 회전하면서 지그재그로 바뀌고 있습니다. 어떻게 해결할 수 있습니까? 또한 단지 왼쪽이나 오른쪽으로 회전 할 때만 시작점에서부터 왼쪽이나 오른쪽으로 움직입니다. 나는 Imageview를 왼쪽이나 오른쪽으로 움직일 때 항상 회전 시키길 원합니다. 위의 링크를 보았습니다. 정확하게 그 모양을 원해주세요. 올바른 방향으로보고 가이드하십시오. –
- 1. UIImageView를 회전하는 방법
- 2. 이미지를 왼쪽 또는 오른쪽으로 슬라이드
- 3. UIImageView를 증분 회전하는 방법은 무엇입니까?
- 4. Android 왼쪽 또는 오른쪽으로 스 와이프 하시겠습니까?
- 5. 한 단어를 Mac에서 왼쪽 또는 오른쪽으로 이동
- 6. JTable의 열 머리글을 왼쪽 또는 오른쪽으로 정렬하는 방법
- 7. 고정 점으로 UIIMageVIew를 회전하는 방법은 무엇입니까?
- 8. 레이아웃 또는 컨테이너에서 왼쪽 또는 오른쪽으로 플로팅 하시겠습니까?
- 9. 쿼리에 왼쪽 및 오른쪽으로 합치기
- 10. 메모장에서 강조 표시된 줄을 왼쪽 또는 오른쪽으로 이동하는 방법이 있습니까? ++
- 11. div가있는 레이아웃을 왼쪽 또는 오른쪽으로 띄우면 작동하지 않습니다.
- 12. ImageView를 가운데에 놓은 다음 왼쪽 또는 오른쪽으로 오프셋하는 방법은 무엇입니까?
- 13. Java Box Class : Unsolvable : 컴포넌트를 왼쪽 또는 오른쪽으로 정렬
- 14. 계속 div 왼쪽/오른쪽으로 계속 이동
- 15. iPhone :보기가 가로보기로 회전하는 것을 방지하는 방법?
- 16. jQuery : 슬라이드 왼쪽 및 오른쪽으로 슬라이드
- 17. 비디오 세로를 가로로 회전하는 방법
- 18. 손가락을 따르는 UIButton 또는 UIImage보기를 회전하는 방법 (길게 터치)?
- 19. ControlDesigner를 사용하여 왼쪽 및 오른쪽으로 도킹을 허용하는 방법
- 20. ios에서 uiimageview를 인코딩하는 방법
- 21. UIImageView를 어둡게하는 방법
- 22. 동적 UIImageView를 만드는 방법
- 23. UIImageView를 그리는 방법 -drawRect :?
- 24. 가로 스크롤을 크기를 왼쪽이나 오른쪽으로 옮기는 방법?
- 25. JXImagePanel을 회전하는 방법?
- 26. 두 개의 UILabels을 왼쪽 및 오른쪽으로 나란히 놓습니다. 왼쪽 레이블의 문자열 길이를 알지 못합니다.
- 27. 표준 마우스로 Netbeans에서 왼쪽 및 오른쪽으로 스크롤 할 수 있습니까?
- 28. iPhone : UIView의 왼쪽 위 좌표를 얻는 방법?
- 29. UIView에서 하나의 요소 만 회전하는 방법
- 30. WPF 창을 회전하는 방법?
WiggleImageView 란 무엇입니까? –
다른 사용자 정의 클래스. 앱을 제거 할 때 스프링 보드와 같은 흔들림 효과를 만드는 것이 었습니다. 그것은 당신의 문제와 관련이 없습니다. rotateRight 및 rotateLeft 메서드와 자체 터치 메서드를 살펴보고 싶습니다. 이러한 메서드는 뷰의 시각적 표시를 회전시키고 뷰가 표시하는 실제 이미지에는 영향을 미치지 않습니다. 즉, 뷰를 저장하거나 다른 뷰에 합성하면 이미지의 원래 방향을 얻게됩니다. – TechZen
이제 괜찮아요. 볼을 만들어서 화면의 맨 위에서 바닥으로 보냅니다. 이걸로 3 개의 이미지 (3 개의 볼과 같은 이미지)를 찍었습니다. 이제 무작위로 볼을 선택할 수 있습니다. 그래서 어떻게 볼을 찾을 수 있습니까? 교차 했나요? –