画面全体でUITextFields、UILabelsなどを移動する状況があるサンプルアプリケーションを開発しています.これを実装するためのリソースを見つけることができません.親切に私に同じ解決策を提案してください.
UITextField にこのように実装したい
よろしくお願いします。 すべてのstackoverflowユーザー向けのメリークリスマスと高度な新年の願い
画面全体でUITextFields、UILabelsなどを移動する状況があるサンプルアプリケーションを開発しています.これを実装するためのリソースを見つけることができません.親切に私に同じ解決策を提案してください.
UITextField にこのように実装したい
よろしくお願いします。 すべてのstackoverflowユーザー向けのメリークリスマスと高度な新年の願い
ドラッグに関する優れたチュートリアルが既にあるので、問題は UIView ではなく UITextField をドラッグしようとしたときに表示されるキーボードであると想定します。解決策は非常に簡単です: myTextField.userInteractionEnabled = NO;
- ユーザーの操作を無効にし、「読み取り専用」にする必要があります。おそらく、すべてのテキスト フィールドがこのフラグ セットを取得する編集モードを持っているでしょう。問題が発生する場合は、textField を UIView に追加し、userInteractionEnabled を false に設定します。次に、UIView をドラッグすると、テキスト フィールドも一緒にドラッグされます。
お役に立てば幸いです。あなたもハッピー ホリデーを!
私はマイケルの提案に従い、解決策を得ました。以下のコードスニペットを提供しました。これは、同じものを実装する必要がある人に役立ちます。
手順:
Windows ベースのアプリケーションを選択し、UIViewController サブクラスを作成して appdelegate ファイルのウィンドウに追加します。
作成したViewControllerクラスのXIBにUIViewを追加し、作成したUIViewにテキストフィールドなどのコントロールを追加します。これらのビューのみを移動するので、View Controllerサブクラスの.hファイルにIBOutletsを追加しますそれに応じて IB にマップします。
サンプルコード
appdelegate.h
#import <UIKit/UIKit.h>
#import "MyView.h"
@interface MyAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
MyView *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
appdelegate.m
#import "MyAppDelegate.h"
@implementation MyAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch.
viewController=[[MyView alloc]init];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end
viewcontroller.h
#import <UIKit/UIKit.h>
@interface MyView : UIViewController {
IBOutlet UIView *textFieldView;
IBOutlet UIView *labelView;
}
@end
viewcontroller.m
#import "MyView.h"
@implementation MyView
- (void)viewDidLoad {
[self.view addSubview:textFieldView];
[self.view addSubview:labelView];
[super viewDidLoad];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
// get touch event
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if ([touch view] == textFieldView) {
// move the image view
textFieldView.center = touchLocation;
}
if ([touch view] == labelView) {
// move the image view
labelView.center = touchLocation;
}
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
ありがとうございました。素敵な時間をお過ごしください。