Tôi có thể sử dụng trình xử lý UIPinchGestureRecognizer
để làm việc với việc chia tỷ lệ đối tượng nhưng tôi không muốn mở rộng quy mô Tôi muốn thay đổi kích thước. Ví dụ: tôi có một số UITextView
và tôi đã đính kèm một cử chỉ UIPinchGestureRecognizer
cho nó và nếu người dùng ghim tôi muốn thay đổi chiều rộng của chế độ xem văn bản để khớp với chụm. Tôi không muốn mở rộng quy mô để số UITextView
lớn hơn (thu phóng).Làm cách nào tôi có thể sử dụng thu phóng pinch (UIPinchGestureRecognizer) để thay đổi chiều rộng của UITextView?
Trả lời
Tôi nghĩ rằng những gì bạn muốn làm là chỉ cần nhân rộng của khung của TextView của mình với quy mô cử chỉ nhận dạng của:
CGFloat scale = gestureRecognizer.scale;
CGRect newFrame = textView.frame;
newFrame.size = CGSizeMake(scale*newFrame.size.width, newFrame.size.height);
textView.frame = newFrame;
Hoặc không phải là những gì bạn này nghĩa là gì?
Điều đó dường như không hoạt động. Uitextview phát triển rất nhanh và bị trì hoãn. Tỷ lệ có thể từ 0-20 + –
Rất tiếc ... Tôi sẽ không mong đợi điều đó. Tôi chưa bao giờ thực sự sử dụng trình nhận dạng cử chỉ ... –
tại sao không xóa câu trả lời này? –
Tôi đang làm điều tương tự. Tôi sẽ cập nhật bài đăng này nếu tôi tìm thấy cách thực hiện.
Hãy thử điều này, nó làm việc cho tôi (cho UIView):
- (IBAction)handlePinchGesture:(UIGestureRecognizer *)sender {
static CGRect initialBounds;
UIView *_view = sender.view;
if (sender.state == UIGestureRecognizerStateBegan)
{
initialBounds = _view.bounds;
}
CGFloat factor = [(UIPinchGestureRecognizer *)sender scale];
CGAffineTransform zt = CGAffineTransformScale(CGAffineTransformIdentity, factor, factor);
_view.bounds = CGRectApplyAffineTransform(initialBounds, zt);
return;
}
Điều gì thực sự giúp tôi là _view.bounds = CGRectApplyAffineTransform (initialBounds, zt); Tự hỏi cho giờ tại sao kích thước bị ràng buộc của tôi đã không thay đổi .. Cảm ơn rất nhiều! – Oritm
rất nhiều lỗi trong mã này. – user2083364
luôn gặp sự cố khi chạy mã này ... – HoangNA
Tôi có bốn thói quen mà đối phó với véo của một trường văn bản. Trình nhận biết cử chỉ là thói quen cốt lõi. Nó sẽ thấy nếu các trường văn bản được chọn sẽ bị Khóa ra khỏi Màn hình, tôi không muốn điều đó. Nếu không, thì tôi bảo nó tự chụm với thang đo từ cử chỉ. Nếu có nhiều lựa chọn, tôi sẽ gửi một thông báo cho những người không bị bẻ khóa màn hình để tự nhéo.
//--------------------------------------------------------------------------------------------------------
// pinchElement
// Description: Called to di the element scale, in our case, we are adjusting the length.
//
//--------------------------------------------------------------------------------------------------------
- (void)pinchElement:(CGFloat)scale {
//Grab how big we are now
CGRect textFieldBounds = textField.bounds;
//Multiple the Scale of the Pinch by the Width to get our new width.
CGFloat newWidth = textFieldBounds.size.width * scale;
CGFloat widthChange = newWidth - textFieldBounds.size.width;
CGRect newBounds = CGRectMake(0, 0, newWidth, textFieldBounds.size.height);
[textField setBounds: newBounds];
[textField setCenter: CGPointMake(textField.center.x + widthChange/2, textField.center.y)] ;
[self contentSizeChanged];
}
//--------------------------------------------------------------------------------------------------------
// pinchOffScreen
// Description: Called to see if the Pinch Gesture will cause element to go off screen Gesture
//
//--------------------------------------------------------------------------------------------------------
- (BOOL)pinchOffScreen:(CGFloat)scale {
//Grab how big we are now
CGRect textFieldBounds = textField.bounds;
//Multiple the Scale of the Pinch by the Width to get our new width.
CGFloat newWidth = textFieldBounds.size.width * scale;
//Figure out our Change in Width so we can calculate our new Zen Center
CGRect newElementBounds = CGRectMake(0, 0, newWidth+ kElementFrameOffset*2 + kElementContentFrameOffset*2, textFieldBounds.size.height + kElementFrameOffset*2 + kElementContentFrameOffset*2);
//We want to be sure that we dont size beyond our bounds, find our Parent Origin.
CGRect elementBoundsInSuperView = [self convertRect:newElementBounds toView:[self superview]];
CGFloat xPosition = CGRectGetMidX(elementBoundsInSuperView);
CGFloat yPosition = CGRectGetMidY(elementBoundsInSuperView);
BOOL offScreen = [self calcOffEditorFromXposition:xPosition yPosition:yPosition fromBoundsInSuperView:elementBoundsInSuperView];
return offScreen;
}
//--------------------------------------------------------------------------------------------------------
// handlePinchGesture
// Description: Called when we get a Pinch Gesture
// We want to override the default scaling and set the width.
//
//--------------------------------------------------------------------------------------------------------
- (void)handlePinchGesture:(UIPinchGestureRecognizer *)gestureRecognizer {
if (IoUIDebug & IoUIDebugSelectorNames) {
NSLog(@"%@ - %@", INTERFACENAME, NSStringFromSelector(_cmd));
}
// UIView *element = [gestureRecognizer view];
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
//We are resizing, Select ourself
[self selectSelf];
}
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {
NSSet *selectedElements = [[(IoScreenEditorViewController *)UIAppDelegate.ioMainViewController.currentViewController editorContentViewController] selectedElements];
BOOL aSelectedElementOffscreen = FALSE;
for (IoUIScreenElement* element in selectedElements) {
if ([element pinchOffScreen:[gestureRecognizer scale]]) {
aSelectedElementOffscreen = TRUE;
break;
}
}
if (!aSelectedElementOffscreen) {
[self pinchElement:[gestureRecognizer scale]];
// Let others know they are moving if they are selected
// Setup our data for the Notification
NSMutableDictionary *theUserInfo = [[[NSMutableDictionary alloc] initWithCapacity:1] autorelease];
[theUserInfo setObject:self forKey:@"ElementWithGesture"];
NSNumber * scaleAsNumber = [[NSNumber alloc] initWithFloat:[gestureRecognizer scale]];
[theUserInfo setValue:scaleAsNumber forKey:@"GestureScale"];
[theUserInfo setObject:gestureRecognizer forKey:@"TheGestureRecognizer"];
[scaleAsNumber release];
// Post the Group Rotation Notification.
[[NSNotificationCenter defaultCenter] postNotificationName:kNCSEGroupPinchGesture
object:nil
userInfo:theUserInfo];
}
[gestureRecognizer setScale:1];
}
if ([gestureRecognizer state] == UIGestureRecognizerStateEnded) {
}
}
//--------------------------------------------------------------------------------------------------------
// groupHandlePinchGesture:
// Description: For a groupPinch Notification. Move it! within bounds of course
//
//--------------------------------------------------------------------------------------------------------
- (void) groupHandlePinchGesture:(NSNotification*)notification{
if (IoUIDebug & IoUIDebugSelectorNames) {
NSLog(@"%@ - %@", INTERFACENAME, NSStringFromSelector(_cmd));
}
IoUIScreenElement *element = (IoUIScreenElement *) [[notification userInfo] objectForKey:@"ElementWithGesture"];
//UIRotationGestureRecognizer *gestureRecognizer = (UIRotationGestureRecognizer *) [[notification userInfo] objectForKey:@"TheGestureRecognizer"];
NSNumber *scaleAsNumber = [[notification userInfo] valueForKey:@"GestureScale"];
CGFloat scale = [scaleAsNumber floatValue];
if (IOFNOTEQUAL(self, element) & [self isSelected]){
[self pinchElement: scale];
}
}
Bạn phải sử dụng trong nhanh chóng:
func pinchgsterAction(gesture:UIPinchGestureRecognizer){
if (gesture.state == UIGestureRecognizerState.Changed) {
let scale:CGFloat = gesture.scale
gesture.view.transform = CGAffineTransformScale(gesture.view.transform, scale, scale)
}
}
- 1. Làm cách nào để làm cho ImageView của tôi có thể thu phóng?
- 2. Tôi có thể ngừng thay đổi kích thước của các yếu tố trên thu phóng không?
- 3. Android WebView sử dụng setWideViewPort, vô hiệu hóa thu phóng bằng hai lần nhấn nhưng giữ thu phóng bằng pinch?
- 4. Thay đổi biểu tượng dựa trên mức thu phóng
- 5. Cách đặt lại mức thu phóng của UIWebView? Tôi đã sử dụng scalesPagesToFit = YES;
- 6. Tôi làm cách nào để databind Chiều rộng của Chiều rộng hoặc Độ rộng của hàngDefID?
- 7. cách đặt điểm neo cho chế độ thu phóng pinch (GMGridView)
- 8. Làm cách nào để thay đổi mức thu phóng của bản đồ Google theo lập trình?
- 9. Tôi có thể sử dụng UIPinchGestureRecognizers để phân biệt giữa pinch ngang và dọc không?
- 10. Làm cách nào để tôi lập trình thu phóng UIScrollView?
- 11. Tôi làm cách nào để tìm chiều rộng của hình ảnh bằng cách sử dụng PHP?
- 12. ios - Chụm/thu phóng từ tỷ lệ hiện tại
- 13. Làm cách nào để tôi có thể chọn UITextView?
- 14. UIScrollView - khi bật phân trang, tôi có thể "thay đổi" chiều rộng của trang không?
- 15. Thay đổi chiều rộng của UIBarButtonItem
- 16. phát hiện pinch để phóng to trên iOS
- 17. Highstocks - Cách thay đổi Thu phóng mặc định
- 18. Thay đổi mức thu phóng của trình duyệt
- 19. Làm cách nào để xác định mức thu phóng hiện tại của cửa sổ trình duyệt?
- 20. Đặt lại tỷ lệ/chiều rộng/thu phóng của Safari trên iPhone bằng JavaScript/onorientationchange
- 21. Làm cách nào để thay đổi chiều rộng lưới của Bootstrap Twitter?
- 22. D3 làm thế nào để thay đổi chiều rộng và chiều dài của SVG
- 23. JqGrid Làm cách nào để thay đổi chiều rộng của biểu mẫu chỉnh sửa?
- 24. UITextView Auto Chiều cao
- 25. Làm cách nào để thu phóng nội dung IFRAME mà không cần sử dụng bộ khung?
- 26. Làm cách nào tôi có thể bật thu phóng trên UIWebView bên trong UIScrollView?
- 27. Tôi làm cách nào để hủy yêu cầu lát bản đồ nổi bật bằng OpenLayers khi thu phóng thay đổi?
- 28. Spinner Primefaces - Cách thay đổi chiều rộng
- 29. làm cách nào để tôi có thể thay đổi DOCTYPE
- 30. ZPL - làm cách nào chúng tôi có thể tăng chiều rộng mã vạch^BC (Mã 128)
Bạn không nên tấn công UIPinchGestureRecognizers khả năng tự vệ: P –
@KennyTM Haha! Tốt nhất ... –
@Jongsma Tại sao không? Nó có thể đã ép anh ta đầu tiên! –