3

scrolling を作成するにはどうすればよいですUIToolbarか? キーボードの上に追加のアクセサリ ボタンがあり、その幅をスクロールすることもできますか? Day One や Byword のように。

編集:私はで使用していますUITextView

Byword から

ここに画像の説明を入力

これは、入力アクセサリ ビューで行ったことです。既にバー ボタン項目を実装しています。水平方向にスクロールして、より多くのボタンを表示できるかどうかに興味があります。

ここに画像の説明を入力

4

5 に答える 5

5

scrollview 内のすべてのボタンを含む 1 つのビューを作成し、そのビューを inputAccessoryView または TextField として割り当てます。あなたが私の答えを得ることを願っています。

于 2013-08-16T04:00:25.827 に答える
4

要件に基づいていくつかのバー ボタンを作成し、それらを配列に追加します。ビュー内にスクロールビューを作成します。そして、スクロールビューを入力アクセサリビューとしてテキストフィールドに与えます。

例を次に示します。 1. 要件に基づいてバー ボタンを作成します。

UIBarButtonItem* button1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done:)];
    UIBarButtonItem* button2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(done:)];
    UIBarButtonItem* button3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(done:)];
    UIBarButtonItem* button4 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(done:)];
    UIBarButtonItem* button5 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRedo target:self action:@selector(done:)];
  1. それらを配列に追加する

     NSArray *itemsArray = [NSArray arrayWithObjects:button1,button2,button3,button4,button5,nil];
    
  2. UIView 内にスクロールビューを作成する

    UIScrollView *scrollView = [[UIScrollView alloc] init];
    scrollView.frame = toolbar.frame;
    scrollView.bounds = toolbar.bounds;
    scrollView.autoresizingMask = toolbar.autoresizingMask;
    scrollView.showsVerticalScrollIndicator = true;
    scrollView.showsHorizontalScrollIndicator = true;
    scrollView.scrollEnabled = YES;
    
    //scrollView.bounces = false;
    UIView *superView = toolbar.superview;
    [toolbar removeFromSuperview];
    toolbar.autoresizingMask = UIViewAutoresizingNone;
    toolbar.frame = CGRectMake(0, 0, 400, toolbar.frame.size.height);
    toolbar.bounds = toolbar.frame;
    [toolbar setItems:itemsArray];
    scrollView.contentSize = toolbar.frame.size;
    [scrollView addSubview:toolbar];
    [superView addSubview:scrollView];
    
  3. inputAccessoryViewtextFieldに scrollview を追加する

    self.textField.inputAccessoryView = scrollView;

于 2019-01-29T11:22:12.150 に答える
1

テキストの編集を開始するときに、uiview アニメーションを設定する必要があります。

[UIView beginAnimations:nil context:nil];
CGRect rect=self.view.frame;
rect.origin.y=-50;
self.view.frame=rect;
[UIView commitAnimations];

編集終了後

[UIView beginAnimations:nil context:nil];
CGRect rect=self.view.frame;
rect.origin.y=0;
self.view.frame=rect;
[UIView commitAnimations];
于 2013-08-16T04:46:31.397 に答える