2011-03-24 65 views
0

,當我按下它,我可以改變自由地查看如何使一個文本框移動

位置 - (IBAction爲)地址:(ID)發送{

CGRect frame = CGRectMake(kLeftMargin, 8.0, kTextFieldWidth, kTextFieldHeight); 

UITextField * textfieldToAdd = [[[UITextField alloc] initWithFrame:frame] autorelease]; 






     textfieldToAdd.borderStyle = UITextBorderStyleRoundedRect; 
     textfieldToAdd.textColor = [UIColor blackColor]; 

     textfieldToAdd.font = [UIFont systemFontOfSize:17.0]; 
     textfieldToAdd.placeholder = @""; 
     textfieldToAdd.backgroundColor = [UIColor whiteColor]; 
     textfieldToAdd.autocorrectionType = UITextAutocorrectionTypeNo ; // no auto correction support 

     textfieldToAdd.keyboardType = UIKeyboardTypeDefault; // use the default type input method (entire keyboard) 
     textfieldToAdd.returnKeyType = UIReturnKeyDone; 

     textfieldToAdd.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right 

     textfieldToAdd.tag = kViewTag;  // tag this control so we can remove it later for recycled cells 

     textfieldToAdd.delegate = self; // let us be the delegate so we know when the keyboard's "Done" button is pressed 

     // Add an accessibility label that describes what the text field is for. 
     [textfieldToAdd setAccessibilityLabel:NSLocalizedString(@"textfieldToAdd", @"")]; 



[self.view addSubview:textfieldToAdd]; 

}

+0

你能對您的問題展開,並用一個例子詳細介紹一下。同時顯示你到目前爲止所嘗試過的。 – gideon 2011-03-24 14:11:20

+0

http://www.flickr.com/photos/[email protected]/5556005854/ – YasBES 2011-03-24 14:19:47

+0

你想拖動文本框? – malinois 2011-03-24 14:24:52

回答

1

先加在gestureRecognizer您viewDidLoad中,然後創建功能
或更好看這裏MoveME example

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panPiece:)]; 
[panGesture setMaximumNumberOfTouches:2]; 
[panGesture setDelegate:self]; 
[self addGestureRecognizer:panGesture]; 

- (void)panPiece:(UIPanGestureRecognizer *)gestureRecognizer 
{ 
    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer  state] == UIGestureRecognizerStateChanged) { 
     CGPoint translation = [gestureRecognizer translationInView:self.view]; 
     textfieldToAdd.center = CGPointMake([self center].x + translation.x, [self center].y + translation.y); 
     [gestureRecognizer setTranslation:CGPointZero inView:[self superview]]; 
    } 
} 
+0

我有很多問題,你能幫我請 – YasBES 2011-03-25 11:01:35

+0

@PasstissiPhone沒有的東西不是一個結構或聯合 – Seega 2011-03-25 11:13:46

+0

@Seega請求移動你的文本框然後,這個小錯誤,你應該自己解決 – YasBES 2011-03-25 13:34:22

0

我想拖動此TextField

  • (無效)viewDidLoad中{

self.navigationItem.rightBarButtonItem = [[[ALLOC的UIBarButtonItem] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd目標:自動作:@selector(添加:) ] autorelease];

}

- (IBAction爲)地址:(ID)發送{

CGRect frame = CGRectMake(kLeftMargin, 8.0, kTextFieldWidth, kTextFieldHeight); 

UITextField * textfieldToAdd = [[[UITextField alloc] initWithFrame:frame] autorelease]; 






     textfieldToAdd.borderStyle = UITextBorderStyleRoundedRect; 
     textfieldToAdd.textColor = [UIColor blackColor]; 

     textfieldToAdd.font = [UIFont systemFontOfSize:17.0]; 
     textfieldToAdd.placeholder = @""; 
     textfieldToAdd.backgroundColor = [UIColor whiteColor]; 
     textfieldToAdd.autocorrectionType = UITextAutocorrectionTypeNo ; // no auto correction support 

     textfieldToAdd.keyboardType = UIKeyboardTypeDefault; // use the default type input method (entire keyboard) 
     textfieldToAdd.returnKeyType = UIReturnKeyDone; 

     textfieldToAdd.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right 

     textfieldToAdd.tag = kViewTag;  // tag this control so we can remove it later for recycled cells 
     textfieldToAdd.delegate = self; // let us be the delegate so we know when the keyboard's "Done" button is pressed 

     // Add an accessibility label that describes what the text field is for. 
     [textfieldToAdd setAccessibilityLabel:NSLocalizedString(@"textfieldToAdd", @"")]; 





[self.view addSubview:textfieldToAdd]; 

}

+0

http:// www。 flickr.com/photos/[email protected]/5556005854 – YasBES 2011-03-25 11:36:20

+0

是的,但我的代碼有什麼問題?發生了什麼,不會發生? – Seega 2011-03-25 12:28:05

相關問題