我在我的视图控制器中创建了一个视图,我希望当我加载该子视图或显示它可能从orignial视图控制器的左侧到右侧时,
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];
我想在按钮单击时打开此视图我想要在单击按钮时,此视图应从左到右滑动,因为通常会打开新的视图控制器。
答案 0 :(得分: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];
使用它。希望帮助
答案 1 :(得分: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);
}];
}