ボタンAをタップしたら、ラベル(非表示設定済)を表示。そのラベルをパン(指先で移動)させるようにする。
ストーリーボード上に、部品を配置。コードに結ぶ。
- ボタン:アクション:startLabel
- ラベル:アウトレット:myLabel
//画面に見える状態で表示される
- (IBAction)startLabel:(id)sender {
//ラベルの装飾モロモロ
self.myLabel.backgroundColor = [UIColor yellowColor];
self.myLabel.layer.borderColor = [UIColor blackColor].CGColor;
self.myLabel.layer.borderWidth = 1.0;
self.myLabel.hidden = NO; //表示する
}
--------------------------------------------------------------------------
ストーリーボード画面にした状態で、
部品欄から「Pan Gesture」を → ラベル上にドラッグして配置。
下のドッグに表示されている、「Pan Gesture(丸が2つ横並びの形アイコン)」を、.hコード上にドラッグしてアクションを設定
- アクション:doPan
.h
//パン用
- (IBAction)doPan:(id)sender;
.m
//パン用
- (IBAction)doPan:(id)sender {
CGPoint tranxlation = [sender translationInView:self.view];
CGPoint center = self.myLabel.center;
center.x = center.x + tranxlation.x;
center.y = center.y + tranxlation.y;
self.myLabel.center = center;
[sender setTranslation:CGPointZero inView:self.view];
}
« Segueで値渡し 画面A→画面B。画面B→画面A | トップページ | 1タップ、2タップ コード »
「MacMini」カテゴリの記事
- iTunesの iTunes Mediaの 保存先ドライブの場所変更(2017.12.11)
- itunes 一時停止 ショートカット 【スペースキー】(2017.11.08)
- Mac→Win への zip ファイルが文字化け・・解消へ(2017.06.30)
- mini で 小さな文字表示の設定画面を拡大する方法(ズーム機能)(2017.06.10)
- アプリ:キンドル 画面左上をタップで、ツールバー表示(2017.06.10)
コメント