在iphone 4 sdk中,如何让TransitionCurlUp触发随机文本?
我正在尝试组装一个应用程序,该应用程序具有一组文本,当用户按下按钮翻页时可以将这些文本随机化。基本上,按下按钮会做两件事;翻转页面并将文本更改为随机包含的短语。
我试图通过将页面卷曲到同一个 XIB 文件中并仅更改文本来实现此目的。卷页可以工作,但不会改变文本。不确定我在这里做错了什么
这是我的代码:
@implementation InfoViewController
@synthesize isViewPushed;
// Implement viewDidLoad to do additional setup after loading the view.
- (void)viewDidLoad {
if(isViewPushed == NO) {
{ UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(200, 300, 100, 50);
[btn setTitle:@"Next" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(cancel_Clicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
{ UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(20, 300, 100, 50);
[btn setTitle:@"Previous" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(next_clicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
int text = rand() % 5;
switch (text) {
case 0:
textview.text = @"Hello 1" ;
break;
case 1:
textview.text = @"Hello 2" ;
break;
case 2:
textview.text = @"Hello 3" ;
break;
case 3:
textview.text = @"Hello 4" ;
break;
case 4:
textview.text = @"Hello 5" ;
break;
}
}
}
-(void) cancel_Clicked:(id)sender {
[self.navigationController dismissModalViewControllerAnimated:YES];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[UIView commitAnimations];
}
-(void) next_clicked:(id)sender {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIView commitAnimations];
}
任何帮助都会很棒。
I am trying to put together an app that has a set of text that can be randomized when the user presses the button to flip the page. Basically, pressing the button does two things; flip the page and changes the text to a randomly included phrase.
I am trying to implement this by having the page curl into the same XIB file and just have the text change. The page curl works but it is not changing the text. Not sure what I am doing wrong here
Here is my code:
@implementation InfoViewController
@synthesize isViewPushed;
// Implement viewDidLoad to do additional setup after loading the view.
- (void)viewDidLoad {
if(isViewPushed == NO) {
{ UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(200, 300, 100, 50);
[btn setTitle:@"Next" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(cancel_Clicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
{ UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(20, 300, 100, 50);
[btn setTitle:@"Previous" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(next_clicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
int text = rand() % 5;
switch (text) {
case 0:
textview.text = @"Hello 1" ;
break;
case 1:
textview.text = @"Hello 2" ;
break;
case 2:
textview.text = @"Hello 3" ;
break;
case 3:
textview.text = @"Hello 4" ;
break;
case 4:
textview.text = @"Hello 5" ;
break;
}
}
}
-(void) cancel_Clicked:(id)sender {
[self.navigationController dismissModalViewControllerAnimated:YES];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[UIView commitAnimations];
}
-(void) next_clicked:(id)sender {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIView commitAnimations];
}
Any help would be so great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不明白你在哪里设置文本值:
或者之后
I don't see where you are setting the text value here:
Or after