iOS를 처음 사용하고 뷰에서 로그인에 문제가 있습니다.
Sign.As Shown in Image의보기를 만들었습니다.
하지만 ScrollView에 뷰를 추가했을 때 로그인 할 수 없습니다. 그래서 내 질문은 뷰 터치에서 스크롤 뷰를 비활성화하는 방법입니다. 이 링크에서 user3182143이 제공 한 UIView 응답에 서명을 그리는 방법 과 동일한 코드를 사용했습니다 .
미리 감사드립니다
나는 당신이 여기서 묻는 것에 대한 대답으로 시도했습니다.
뷰 안에 스크롤을 설정 한 다음 뷰에 쓰려고했지만 그렇게 할 수 없었고 그 후 스크롤을 숨겼습니다. 이제 작동합니다.
SignatureDrawView.h
#import <UIKit/UIKit.h>
@interface SignatureDrawView : UIView
@property (nonatomic, retain) UIGestureRecognizer *theSwipeGesture;
@property (nonatomic, retain) UIImageView *drawImage;
@property (nonatomic, assign) CGPoint lastPoint;
@property (nonatomic, assign) BOOL mouseSwiped;
@property (nonatomic, assign) NSInteger mouseMoved;
- (void)erase;
- (void)setSignature:(NSData *)theLastData;
- (BOOL)isSignatureWrite;
@end
SignatureDrawView.m
#import "SignatureDrawView.h"
@implementation SignatureDrawView
@synthesize theSwipeGesture;
@synthesize drawImage;
@synthesize lastPoint;
@synthesize mouseSwiped;
@synthesize mouseMoved;
#pragma mark - View lifecycle
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (id)initWithCoder:(NSCoder*)coder
{
if ((self = [super initWithCoder:coder]))
{
drawImage = [[UIImageView alloc] initWithImage:nil];
drawImage.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
[self addSubview:drawImage];
self.backgroundColor = [UIColor whiteColor];
mouseMoved = 0;
}
return self;
}
#pragma mark touch handling
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches)
{
NSArray *array = touch.gestureRecognizers;
for (UIGestureRecognizer *gesture in array)
{
if (gesture.enabled & [gesture isMemberOfClass:[UISwipeGestureRecognizer class]])
{
gesture.enabled = NO;
self.theSwipeGesture = gesture;
}
}
}
mouseSwiped = NO;
UITouch *touch = [touches anyObject];
lastPoint = [touch locationInView:self];
[[NSNotificationCenter defaultCenter] postNotificationName:@"stopscroll" object:self];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
mouseSwiped = YES;
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self];
UIGraphicsBeginImageContext(self.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 3.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
mouseMoved++;
[[NSNotificationCenter defaultCenter] postNotificationName:@"stopscroll" object:self];
if (mouseMoved == 10) {
mouseMoved = 0;
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if(!mouseSwiped)
{
UIGraphicsBeginImageContext(self.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 3.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
self.theSwipeGesture.enabled = YES;
mouseSwiped = YES;
[[NSNotificationCenter defaultCenter] postNotificationName:@"stopscroll" object:self];
}
#pragma mark Methods
- (void)erase
{
mouseSwiped = NO;
drawImage.image = nil;
}
- (void)setSignature:(NSData *)theLastData
{
UIImage *image = [UIImage imageWithData:theLastData];
if (image != nil)
{
drawImage.image = [UIImage imageWithData:theLastData];
mouseSwiped = YES;
}
}
- (BOOL)isSignatureWrite
{
return mouseSwiped;
}
@end
What I added in above is just I created the post notification for stop the scroll when I touch to signature on view.It is implemented in start,moving and end method.
[[NSNotificationCenter defaultCenter] postNotificationName:@"stopscroll" object:self];
SignatureDrawView.m
Next in ViewController I created the scrollView and UIImageView with UIView.
ViewController.h
#import <UIKit/UIKit.h>
#import "SignatureDrawView.h"
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIScrollView *scroll;
@property (strong, nonatomic) IBOutlet SignatureDrawView *drawSignView;
@property (strong, nonatomic) IBOutlet UITextField *txtFldDesc;
- (IBAction)actionSave:(id)sender;
- (IBAction)actionClear:(id)sender;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize drawSignView,scroll,txtFldDesc;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
scroll.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height+200);
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopScroll:) name:@"stopscroll" object:nil];
}
- (void)stopScroll:(NSNotification *)notification
{
if([[notification name] isEqualToString:@"stopscroll"])
scroll.scrollEnabled = NO;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)actionSave:(id)sender
{
scroll.scrollEnabled = YES;
// code for save the signature
UIGraphicsBeginImageContext(self.drawSignView.bounds.size);
[[self.drawSignView.layer presentationLayer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *postData = UIImageJPEGRepresentation(viewImage, 1.0);
....Then do your stuff to save this in DB or server
}
- (IBAction)actionClear:(id)sender
{
scroll.scrollEnabled = YES;
//code for clear the signature
[self.drawSignView erase];
}
@end
In above viewDidLoad method I added addObserver for stop scrolling.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopScroll:) name:@"stopscroll" object:nil];
Finally I implemented the stopScroll:
method
Also I set the scroll.scrollEnabled = YES
in actionSave
and actionclear
method
I gave you the solution only after I tried and worked out well.
Check and apply my code.It works fine and perfectly now.
Output Result
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다