0

ビューコントローラーでビューを作成しました。そのサブビューをロードするか、元のビューコントローラーの左から右にロードされる可能性があることを示します

 subView = [[UIView alloc] initWithFrame:CGRectMake(20, 125, 560,530)];

[subView setBackgroundColor:[UIColor colorWithRed:216./255 green:238./255 blue:209./255 alpha:1.0]];


UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
backButton.frame = CGRectMake(40,20, 169,42);
UIImage*btnImage = [UIImage imageNamed:@"back.PNG"];

[backButton setImage:btnImage forState:UIControlStateNormal];

[backButton addTarget:self action:@selector(backButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

[subView addSubview:backButton];

[self.view addSubview:subView];

ボタンをクリックしてこのビューを開きたい ボタンをクリックすると、通常は新しいビューコントローラーが開くので、このビューが左から右にスライドして画面に表示されるようにします。

4

2 に答える 2

0

UIView アニメーション ブロックを使用する

- (IBAction)backButtonClicked:(id)sender {
    [UIView animateWithDuration:1.0f animations:^{
        CGRect frame = CGRectMake(subview.frame.size.width, subview.frame.origin.y, subview.frame.size.width, subview.frame.size.height);
        subview.frame = frame;
    } completion:^(BOOL finished) {
        CGRect frame = CGRectMake(320.0, subview.frame.origin.y, subview.frame.size.width, subview.frame.size.height);
        subview.frame = CGRectMake(20, 125, 560,530);       
    }];
}
于 2012-08-06T09:15:34.663 に答える
0
subView = [[UIView alloc] initWithFrame:CGRectMake(320, 125, 560,530)];

[subView setBackgroundColor:[UIColor colorWithRed:216./255 green:238./255 blue:209./255 alpha:1.0]];


UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
backButton.frame = CGRectMake(40,20, 169,42);
UIImage*btnImage = [UIImage imageNamed:@"back.PNG"];

[backButton setImage:btnImage forState:UIControlStateNormal];

[backButton addTarget:self action:@selector(backButtonClicked:)     forControlEvents:UIControlEventTouchUpInside];

[subView addSubview:backButton];

[self.view addSubview:subView];

ボタンをクリックすると、関数に以下のコードを記述します

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
subView.frame = CGRectMake(20, 125, 560,530);
[UIView commitAnimations];

これを使って。希望が役立ちます

于 2012-08-06T09:10:45.497 に答える