我正在尝试在xcode中创建一个翻页应用程序。页面旋转对于横向右侧工作正常,但对于横向左侧,页面卷曲从左侧发生。我添加了一个容器视图,然后左边的横向页面卷曲开始从底部发生而不是从右边发生。
我在这里找到了一些建议(http://stackoverflow.com/questions/4780488/i-want-to-use-animation-to-imageview-using-uianimationtransitioncurl-right-or-lef)和这里(http: //stackoverflow.com/questions/4780488/i-want-to-use-animation-to-imageview-using-uianimationtransitioncurl-right-or-lef)
但这两个建议都是旧式的页面转换代码,而不是块代码。我尝试用新的块样式代码修改它们,但它对我不起作用。
我在这里附上我的代码:
- (void)viewDidLoad
{
UIImage *img = [UIImage imageNamed:@"s1p1.png"];
currentView.image = img;
img = [UIImage imageNamed:@"s1p2.png"];
swapView.image = img;
UISwipeGestureRecognizer *nextPage;
nextPage = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(turnPage)] autorelease];
if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft) {
[nextPage setDirection:UISwipeGestureRecognizerDirectionRight];
}
else {
[nextPage setDirection:UISwipeGestureRecognizerDirectionLeft];
}
[self.view addGestureRecognizer:nextPage];
[super viewDidLoad];
}
-(void) turnPage
{
if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft)
{
NSLog(@"landscapeleft");
mainView.transform = CGAffineTransformMakeRotation(M_PI);
currentView.transform = CGAffineTransformMakeRotation(-M_PI);
swapView.transform = CGAffineTransformMakeRotation(-M_PI);
[UIView transitionWithView:mainView
duration:1
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
currentView.hidden = YES;
swapView.hidden = NO;
}
completion:^(BOOL finished){
UIImage *temp = [currentView.image retain];
currentView.image = swapView.image;
swapView.image = temp;
[temp release];
currentView.hidden = NO;
swapView.hidden = YES;
}];
}
else
{
NSLog(@"landscaperight");
[UIView transitionWithView:self.view
duration:1
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
currentView.hidden = YES;
swapView.hidden = NO;
}
completion:^(BOOL finished){
UIImage *temp = [currentView.image retain];
currentView.image = swapView.image;
swapView.image = temp;
[temp release];
currentView.hidden = NO;
swapView.hidden = YES;
}];
}
}
我有两个视图:self.view是窗口的主视图,然后mainView是我的容器视图。 currentView和SwapView是图像视图。
对此有何想法?非常感谢您对此进行审核。