2012-08-15 2 views
1

uiswitch를 추가했으며이를 제스처를 통해 다른 위치로 옮기고 싶습니다. 하지만 uiswitch에 uipangesture 작동하지 않습니다 .. 아래 내가 UIPanGestureRecognizer가 작동하지 않습니다 생각UipanGesture가 Uiswitch에서 작동하지 않습니다.

UISwitch *swich = [[UISwitch alloc]initWithFrame:CGRectMake(20, 20, 40, 50)]; 

    swich.userInteractionEnabled = YES; 

    UIPanGestureRecognizer *gesture = [[UIPanGestureRecognizer alloc] 
             initWithTarget:self 
             action:@selector(switchdraged:)]; 
    [swich addGestureRecognizer:gesture]; 

    [self.view addSubview:swich]; 

라고하지 않을 switchdraged 기능 .. 아래

가 switchdraged 기능 내 코드

- (void)switchdraged:(UIPanGestureRecognizer *) gesture1 
{ 
     UISwitch *swich = (UISwitch *)gesture1.view; 
     CGPoint translation = [gesture1 translationInView:swich]; 
     swich.center = CGPointMake(swich.center.x + translation.x, 
           swich.center.y + translation.y); 
     // reset translation 
     [gesture1 setTranslation:CGPointZero inView:swich]; 
} 
+0

우리는 d labelDragged의 정의 :? –

+0

정의를 추가하십시오. – KsK

+0

개인적으로 이걸 사용하지 않아도됩니다 ..하지만 여기를 볼 수는 있습니다. http://stackoverflow.com/a/6687064/919545이 도움이 되길 바란다면 –

답변

1

입니다 UISwitch.

클래스 참조

UIPanGestureRecognizer은 (드래그) 제스처 패닝을 찾습니다 UIGestureRecognizer 의 구상 서브 클래스 말한다. 사용자는 팬을 움직일 때 뷰에서 하나 이상의 손가락을 번 눌러야합니다.

는 SO UISwitch은 아마 내가 샘플 응용 프로그램

에게 UILabel 대신 UISwitch 잘 작동 동일한 코드를 생성 한 상태

을 변경 무시됩니다. 나는 아비 젠과 협의했다. 그는 그게 내게 말했다 그것은 아마도 상태를 변경하기 위해 무시됩니다.

UISwitch로해야 할 일을 잘 설명하십시오.

- (void)viewDidLoad 
{ 

    UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 100, 100)]; 
    containerView.backgroundColor = [UIColor blackColor]; 
    UIPanGestureRecognizer *gesture = [[UIPanGestureRecognizer alloc] 
             initWithTarget:self 
             action:@selector(switchdraged:)]; 
    [containerView addGestureRecognizer:gesture]; 


    UISwitch *swich = [[UISwitch alloc]initWithFrame:CGRectMake(20, 20, 40, 50)];  
    swich.userInteractionEnabled = YES; 



    [containerView addSubview:swich];  

    [self.view addSubview:containerView]; 
    [self.view bringSubviewToFront:containerView]; 


    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 


- (void)switchdraged:(UIPanGestureRecognizer *) gesture1 
{ 
    NSLog(@"triggered"); 

    UIView *swich = (UIView *)gesture1.view; 
    CGPoint translation = [gesture1 translationInView:swich]; 
    swich.center = CGPointMake(swich.center.x + translation.x, 
           swich.center.y + translation.y); 
    // reset translation 
    [gesture1 setTranslation:CGPointZero inView:swich]; 
} 

또는

이 링크는 당신에게

Draggable Buttons and Labels 도움이 될 수

이 방법은보기 안에 당신에게

1.Create 스위치를 도울 수 있으며, 하위 뷰로 추가

+0

퍼팅보다 스위치 UIView에서 작동해야한다 UIPanGesture 추가 .. –

+0

@AnkitSrivastava : 나는 너무 그걸 추가했습니다 : :) –

+0

음침한 일이 잘 .. 고마워요 Ramshad – KsK