使用开关作为页面转换

时间:2011-10-12 07:56:26

标签: iphone objective-c

如何使用切换或其他方法转换页面,而不是使用滚动?

2 个答案:

答案 0 :(得分:0)

是否要更改过渡样式或使用switch语句或两者都使用? 滚动你的意思是覆盖垂直吗?

更改转换样式go: .M

#import "nextpage.h"
@implementation myproject

-(IBAction)transition:(id)sender {
nextpage *first = [[nextpage alloc]initWithNibName:nil bundle:nil];
first.modaltransitionstyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:first animated:YES];
}

您可以替换

UIModalTransitionStyleFlipHorizontal 

UIModalTransitionStylePartialCurl

UIModalTransitionStyleCoverVertical //default transition style

UIModalTransitionStyleCrossDissolve

如果你想在转换之间切换switch语句需要花费更多精力...... 在这种情况下,每个按钮将具有不同的标签(0,1,2,3),并且它们都连接到IB中的一个动作。这只是因为switch语句不允许你在其中创建变量。 .H

#import "myfile"
@interface myproject UIViewController {
myfile *first;
}
-(IBAction)myaction:(id)sender;

的.m

#import "myfile"
@implementation myproject 
-(IBAction)myaction:(id)sender {
switch ([sender tag])
case 0:
first = [[myfile alloc]initWithNibName:nil bundle:nil];
first.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:first animated:YES];
break;
case 1:
first = [[myfile alloc]initWithNibName:nil bundle:nil];
first.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:first animated:YES];
break;
case 2:
first = [[myfile alloc]initWithNibName:nil bundle:nil];
first.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:first animated:YES];
break;
case 0:
first = [[myfile alloc]initWithNibName:nil bundle:nil];
first.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:first animated:YES];
break;
default:
break;

}

仅切换声明(请不要叫我先生,我比你想的还年轻!))     .M      - (IBAction)myaction:(id)sender {     开关([发送者标签])     情况1:     //你想做什么     打破;     案例2;     //当发件人标签的标签是两个时你想要做什么     打破;     //等等...     默认:     打破;     }

IBAction只是一个出现在Interface Builder的动作部分中的动作(IB = Interface Builder) IBAction用作可以在.m文件中编辑的操作,几乎可以执行任何操作。 如果这不是您想要的答案,请对此答案发表评论。

答案 1 :(得分:0)

·H

@interface myproject : UIViewController {
UIButton *button;
UILabel *label;
}
-(IBAction)action:(id)sender;

的.m

@implementation myproject
-(IBAction)action:(id)sender {
label.text = @"changed";
}
-(void)viewDidLoad {
label = [[UILabel alloc]initWithFrame:CGRectMake (x position, y position, width, height);
button = [[UIButton alloc]initWithFrame:CGRectMake (x position, y position, width, height);
[button setTitle:@"press" forState: UIControlStateNormal];
button = [buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
[self.view addsubView:button];
[self.view addSubView:label];
label.text = @"not changed";
}