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
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 回答
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 回答