开发者

Use a switch as page transition

How do I use a开发者_JS百科 switch or other methods to transition a page, other than using scroll?


Do you want to change the transition style or do use a switch statement or both? And by scroll do you mean cover vertical?

to change the transition style 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];
}

You can replace the

UIModalTransitionStyleFlipHorizontal 

with

UIModalTransitionStylePartialCurl

and

UIModalTransitionStyleCoverVertical //default transition style

and

UIModalTransitionStyleCrossDissolve

If you want a switch statement switching between transitions it takes a bit more effort... in this case, each button will have a different tag (0, 1, 2, 3) and they are all connected to one action in IB. This is simply because the switch statement won't let you make variables inside it. .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;

}

switch statement only (please don't call me sir, I am younger than you think!)) .m -(IBAction)myaction:(id)sender { switch ([sender tag]) case 1: //what you want done break; case 2; //what you want done when the sender tag's tag is two break; //and so on... default: break; }

an IBAction is simply an action that appears in the actions section in Interface Builder (IB= Interface Builder) the IBAction is used as an action that can be edited in the .m file to do virtually anything. If this is not the answer you wanted please make a comment on this answer.


.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";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜