6

アプリで UI がプログラムによって生成されます。UIにはほとんどbuttonsありません。画面の上部からポップアップし、画面の中央にアニメーション化するtexboxesカスタムオブジェクトを開発しました。ポップアップが表示されたら、画面のサイズで別のビュー (ヘルパー ビューと呼ばれる) を描画uidatapickerして、画面内の他のすべての s を除くが無効になるようにします。しかし、UI のボタンをアニメーション化すると、別の場所にジャンプします。また、UI には 3 つのボタンがあります。1 つのボタン (UIView 内の 1 つの UIButton) のみで発生します。他の2つのボタンは問題ありません。また、ボタンのテキストを除いて、これらのボタン間に大きな違いはありません。uidatapickerUIViewuiobjectuidatepickerUIDatePicker

  • 前述のビュー (ヘルパー ビュー) を削除しましたが、まだ問題が発生しています。
  • なぜこれが発生するのかを知る必要があります。
  • また、うまく機能する他のページもたくさんあります。

コード

-(void)openEditDateTime:(UIDatePickerMode) mode {
    if ([clientView viewWithTag:9]) {
        [self cancelPressed];
    }
    CGRect toolbarTargetFrame = CGRectMake((clientView.frame.size.width/2)-160, (clientView.frame.size.height/2)+91, 320, 44);
    CGRect datePickerTargetFrame = CGRectMake((clientView.frame.size.width/2)-160, (clientView.frame.size.height/2)-125, 320, 216);

    backgroundView = [[UIView alloc] initWithFrame:clientView.bounds];
    backgroundView.alpha = 0;
    backgroundView.backgroundColor = [UIColor blackColor];
    backgroundView.tag = 9;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cancelPressed:)];
    [backgroundView addGestureRecognizer:tapGesture];
    [clientView addSubview:backgroundView];
    [self bringToFront:backgroundView];

    datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, self.bounds.size.height+44, 320, 216)];
    datePicker.tag = 10;
    datePicker.datePickerMode = mode;
    [clientView addSubview:datePicker];
    [clientView bringSubviewToFront:datePicker];
    [datePicker becomeFirstResponder];
    [self bringToFront:datePicker];
    if(date != nil){
        datePicker.date = date;
    }

    toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.bounds.size.height, 320, 44)];
    toolBar.tag = 11;
    toolBar.barStyle = UIBarStyleBlackTranslucent;
    UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(donePressed:)];
    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelPressed:)];
    [toolBar setItems:[NSArray arrayWithObjects:spacer, doneButton, cancelButton, nil]];
    [clientView addSubview:toolBar];
    [clientView bringSubviewToFront:toolBar];

    [UIView beginAnimations:@"MoveIn" context:nil];
    toolBar.frame = toolbarTargetFrame;
    datePicker.frame = datePickerTargetFrame;
    backgroundView.alpha = 0.5;
    [UIView commitAnimations];
}


-clientView ですUIScrollView
-backgroundViewは、前述のヘルパー ビューです。

これがボタンを追加する方法です。
すべてのコードを配置する必要はなく、他にも多くの依存関係があるため、ボタン レンダリング コードの一部のみを配置します。

-(RenderedElement*)renderElement:(NSObject*)element:(ParentView*)parent:(PageView*)page:(Page*)modelPage:(RenderedElement*)parentRenderedElement {

    UIButton *buttonView = nil;
    Button *templateElement = nil;
    buttonView = [UIButton buttonWithType:UIButtonTypeCustom];
    [buttonView setLineBreakMode:UILineBreakModeWordWrap];        
    [buttonView addTarget:parent action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; 
    [parent addSubview:buttonView];
}


更新
レンダリングの順序を変更すると、ボタンを最初にレンダリングすると、ジャンプ効果が発生しません。UIは正常に動作します。問題を一時的に解決します。しかし、私はその理由を見つけて、より良い解決策を見つけたいと思っています。

4

3 に答える 3

2

どのボタンが動いているか、実際に言いましたか?もう少し詳細がないと、ちょっと難しいです。しかし、ここにいくつかの提案があります:

日付ピッカーをスタックの一番下に追加してから前に引き出すのではなく、次のようにします。

[clientView addSubview:datePicker];
[clientView bringSubviewToFront:datePicker];

次の方法で追加してみませんか。

[clientView insertSubview:datePicker atIndex:0];

また、datPickerを追加してからそれを前方に引っ張った後、問題のあるボタンが含まれていると思われるツールバーを追加しています。ビュー階層で、ツールバーを日付ピッカーの上に配置しますか?

おそらく次の場所に挿入します。

[clientView insertSubview:toolBar aboveSubview:datePicker];

最後に、ツールバー フレームをアニメーション化する必要がありますか?

于 2013-10-31T13:33:44.223 に答える
2

多分あなたは追加することができます

[UIView setAnimationBeginsFromCurrentState:YES];

[UIView beginAnimations:@"MoveIn" context:nil];
于 2013-10-24T12:03:44.117 に答える
0

私が想像できる唯一のことは、クライアントビューにこのボタンがあるかもしれないということです。これを追加して移動しているので

[clientView addSubview:datePicker];
[clientView bringSubviewToFront:datePicker];

これにより、UIButton のフレームが再調整される場合があります。そして、それはこの手順中に発生するため、ジャンプボタンとして表示される可能性のある動きもアニメーション化します..だから試してみるべきだと思います

[jumpingButton setAnimationsEnabled:NO];  //you-know jumping button is the outlet of the -you-know-who
于 2013-11-07T10:40:51.777 に答える