Objective c에서 UIView 터치시 ScrollView를 비활성화 및 활성화하는 방법

무주

iOS를 처음 사용하고 뷰에서 로그인에 문제가 있습니다. 여기에 이미지 설명 입력

여기에 이미지 설명 입력

Sign.As Shown in Image의보기를 만들었습니다.

하지만 ScrollView에 뷰를 추가했을 때 로그인 할 수 없습니다. 그래서 내 질문은 뷰 터치에서 스크롤 뷰를 비활성화하는 방법입니다. 이 링크에서 user3182143이 제공 한 UIView 응답에 서명을 그리는 방법 과 동일한 코드를 사용했습니다 .

미리 감사드립니다

user3182143

나는 당신이 여기서 묻는 것에 대한 대답으로 시도했습니다.

뷰 안에 스크롤을 설정 한 다음 뷰에 쓰려고했지만 그렇게 할 수 없었고 그 후 스크롤을 숨겼습니다. 이제 작동합니다.

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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

UICollectionViewCell 내에서 UIView를 비활성화하는 방법

분류에서Dev

Linux 및 Windows에서 TeamViewer 서비스를 비활성화 / 활성화하는 방법은 무엇입니까?

분류에서Dev

Vue 구성 API에서 활성화 및 비활성화를 사용하는 방법은 무엇입니까?

분류에서Dev

Linux Debian (Wheezy)에서 장치를 비활성화하는 방법

분류에서Dev

Linux Debian (Wheezy)에서 장치를 비활성화하는 방법

분류에서Dev

Dell 노트북에서 터치 패드를 비활성화 / 활성화 / 토글하는 방법

분류에서Dev

SwiftUI에서 ScrollView Bounce를 비활성화하는 방법

분류에서Dev

요청시 ActionMailer를 활성화 / 비활성화하는 방법

분류에서Dev

Durandal에서 캐시보기를 비활성화하는 방법

분류에서Dev

Java 프로그램에서 KEY_WOW64_32KEY를 활성화 및 비활성화하는 방법

분류에서Dev

버튼 클릭시 jquery dataTables에서 페이징을 활성화 및 비활성화하는 방법

분류에서Dev

NSError 및 JSON 데이터를 폴링하는 동안 활성화-Objective C

분류에서Dev

XWalkView에서 Javascript를 비활성화하고 다시 활성화하는 방법은 무엇입니까?

분류에서Dev

Matlab : 신경망에서 검증 및 테스트 데이터 세트를 비활성화하는 방법

분류에서Dev

명령 줄에서 일시적으로 절전 및 최대 절전 모드를 비활성화하는 방법

분류에서Dev

vscode (python)에서 pylint 경고 및 메시지를 비활성화하는 방법은 무엇입니까?

분류에서Dev

명령 줄에서 일시적으로 절전 및 최대 절전 모드를 비활성화하는 방법

분류에서Dev

Laravel의 시드 파일에서 'create_at'및 'update_at'를 비활성화하는 방법은 무엇입니까?

분류에서Dev

Linux Mint 19.1에서 로그인 및 기타 시스템 사운드를 비활성화하는 방법

분류에서Dev

Quintus에서 터치를 비활성화하는 방법은 무엇입니까?

분류에서Dev

Ubuntu 12.4에서 시작할 때 Bluetooth 장치를 비활성화하는 방법

분류에서Dev

Linux Mint에서 시간 동기화를 비활성화하는 방법

분류에서Dev

web.xml에서 조건부로 필터를 활성화 / 비활성화하는 방법

분류에서Dev

UIView (iOS8 / Swift) 아래에있는 MapView에 대해 터치 이벤트를 활성화하는 방법

분류에서Dev

Eclipse에서 발생 강조 표시를 활성화 / 비활성화하는 방법은 무엇입니까?

분류에서Dev

터치 장치에 대한 링크를 비활성화하는 방법

분류에서Dev

Windows 10에서 PageUp 및 PageDown 키를 비활성화하는 방법

분류에서Dev

Perforce에서 분기를 비활성화 / 비활성화 / 보관하는 방법

분류에서Dev

onclick 이벤트를 활성화 및 비활성화하는 방법

Related 관련 기사

  1. 1

    UICollectionViewCell 내에서 UIView를 비활성화하는 방법

  2. 2

    Linux 및 Windows에서 TeamViewer 서비스를 비활성화 / 활성화하는 방법은 무엇입니까?

  3. 3

    Vue 구성 API에서 활성화 및 비활성화를 사용하는 방법은 무엇입니까?

  4. 4

    Linux Debian (Wheezy)에서 장치를 비활성화하는 방법

  5. 5

    Linux Debian (Wheezy)에서 장치를 비활성화하는 방법

  6. 6

    Dell 노트북에서 터치 패드를 비활성화 / 활성화 / 토글하는 방법

  7. 7

    SwiftUI에서 ScrollView Bounce를 비활성화하는 방법

  8. 8

    요청시 ActionMailer를 활성화 / 비활성화하는 방법

  9. 9

    Durandal에서 캐시보기를 비활성화하는 방법

  10. 10

    Java 프로그램에서 KEY_WOW64_32KEY를 활성화 및 비활성화하는 방법

  11. 11

    버튼 클릭시 jquery dataTables에서 페이징을 활성화 및 비활성화하는 방법

  12. 12

    NSError 및 JSON 데이터를 폴링하는 동안 활성화-Objective C

  13. 13

    XWalkView에서 Javascript를 비활성화하고 다시 활성화하는 방법은 무엇입니까?

  14. 14

    Matlab : 신경망에서 검증 및 테스트 데이터 세트를 비활성화하는 방법

  15. 15

    명령 줄에서 일시적으로 절전 및 최대 절전 모드를 비활성화하는 방법

  16. 16

    vscode (python)에서 pylint 경고 및 메시지를 비활성화하는 방법은 무엇입니까?

  17. 17

    명령 줄에서 일시적으로 절전 및 최대 절전 모드를 비활성화하는 방법

  18. 18

    Laravel의 시드 파일에서 'create_at'및 'update_at'를 비활성화하는 방법은 무엇입니까?

  19. 19

    Linux Mint 19.1에서 로그인 및 기타 시스템 사운드를 비활성화하는 방법

  20. 20

    Quintus에서 터치를 비활성화하는 방법은 무엇입니까?

  21. 21

    Ubuntu 12.4에서 시작할 때 Bluetooth 장치를 비활성화하는 방법

  22. 22

    Linux Mint에서 시간 동기화를 비활성화하는 방법

  23. 23

    web.xml에서 조건부로 필터를 활성화 / 비활성화하는 방법

  24. 24

    UIView (iOS8 / Swift) 아래에있는 MapView에 대해 터치 이벤트를 활성화하는 방법

  25. 25

    Eclipse에서 발생 강조 표시를 활성화 / 비활성화하는 방법은 무엇입니까?

  26. 26

    터치 장치에 대한 링크를 비활성화하는 방법

  27. 27

    Windows 10에서 PageUp 및 PageDown 키를 비활성화하는 방법

  28. 28

    Perforce에서 분기를 비활성화 / 비활성화 / 보관하는 방법

  29. 29

    onclick 이벤트를 활성화 및 비활성화하는 방법

뜨겁다태그

보관