0
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[templatePhotoPlaceholderView addGestureRecognizer:panRecognizer];
-(void)move:(UIPanGestureRecognizer *)gestureRecognizer{
CGPoint translatedPoint = [gestureRecognizer translationInView:imageview];
CGPoint center;
if([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
_firstX = [imageview center].x;
_firstY = [imageview center].y;
if(center.x < templatePhotoPlaceholderView.frame.origin.x + (imageview.frame.size.width/2)){
center.x = templatePhotoPlaceholderView.frame.origin.x+(imageview.frame.size.width/2);
}
if(center.x > templatePhotoPlaceholderView.frame.origin.x+templatePhotoPlaceholderView.frame.size.width - (imageview.frame.size.width/2)){
center.x = templatePhotoPlaceholderView.frame.origin.x+templatePhotoPlaceholderView.frame.size.width - (imageview.frame.size.width/2);
}
if(center.y < templatePhotoPlaceholderView.frame.origin.y + (imageview.frame.size.height/2)){
center.y = templatePhotoPlaceholderView.frame.origin.y + (imageview.frame.size.height/2);
}
if(center.y > templatePhotoPlaceholderView.frame.origin.y + templatePhotoPlaceholderView.frame.size.height -(imageview.frame.size.height/2)){
center.y = templatePhotoPlaceholderView.frame.origin.y + (templatePhotoPlaceholderView.frame.size.height)-(imageview.frame.size.height/2);
}
}
translatedPoint = CGPointMake(center.x+translatedPoint.x, center.y+translatedPoint.y);
[imageview setCenter:translatedPoint];
}
移動圖像如何在指定視圖[templatePhotoPlaceholderView is a view imageview is an UIImageView]
如何在指定的UIView iphone
當圖像觸及的UIView的所有角落的邊緣移動的圖像,然後圖像不必移動。
不允許圖像在UIView的外面。
我嘗試但無法修復指定區域中的圖像視圖以便移動。
@對不起,如果在打字時出現任何語法錯誤。
@all請指教我如何找出問題。
//縮放
UIPinchGestureRecognizer *pinchRecognizer = [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)] autorelease];
[pinchRecognizer setDelegate:self];
[templatePhotoPlaceholderView addGestureRecognizer:pinchRecognizer];
[self.view addSubview:templatePhotoPlaceholderView];
[tapRecognizer release];
- (void)scale:(UIPinchGestureRecognizer *)gestureRecognizer
{
[self adjustAnchorPointForGestureRecognizer:gestureRecognizer];
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {
float hfactor = imageview.frame.size.width/templatePhotoPlaceholderView.frame.size.width;
float vfactor = imageview.frame.size.height/templatePhotoPlaceholderView.frame.size.height;
float factor = MAX(hfactor, vfactor);
if (([gestureRecognizer scale] > 1 && factor < 3) || ([gestureRecognizer scale] <= 1 && factor >1)) {
imageview.transform = CGAffineTransformScale([imageview transform], [gestureRecognizer scale], [gestureRecognizer scale]);
}
[gestureRecognizer setScale:1];
}
}
@all任何一個可以告訴我在哪裏,我錯了。 – user905582