0

旋转后我的视图大小重置有一点问题,我无法修复它。

我在视图“bottomContainerView”上放置了一个“滑动”操作,大小因方向而异!

这是我的新代码:

-(void)swipeToggle:(UISwipeGestureRecognizer *)sender {
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
    if (sender.direction ==  UISwipeGestureRecognizerDirectionUp){

         NSLog(@"if gesture up - LS");

        [UIView animateWithDuration:0.5
                              delay:0.1
                            options:UIViewAnimationOptionCurveEaseInOut
                         animations:^{
                             topContainerView.frame = CGRectMake(0.0, -160.0, 480.0, 244.0);
                             bottomContainerView.frame = CGRectMake(0.0, 0.0, 480.0, 300.0);}
                         completion:^(BOOL finished){
                           NSLog(@"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height);                                   
                         }];

    } else if (sender.direction ==  UISwipeGestureRecognizerDirectionDown) {

        NSLog(@"else if gesture down - LS");

        [UIView animateWithDuration:0.5
                              delay:0.1
                            options:UIViewAnimationOptionCurveEaseInOut
                         animations:^{
                             topContainerView.frame = CGRectMake(0.0, -160.0, 480.0, 244.0);
                             bottomContainerView.frame = CGRectMake(0.0, 84.0, 480.0, 216.0);}
                         completion:^(BOOL finished){
                            NSLog(@"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height); 
                         }];
    }
}
else if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait) {
    if (sender.direction ==  UISwipeGestureRecognizerDirectionUp) {

        NSLog(@"if gesture down - PT");

        [UIView animateWithDuration:0.5
                          delay:0.1
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         topContainerView.frame = CGRectMake(0.0, 0.0, 320.0, 244.0);
                         bottomContainerView.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, 640.0);
                     }
                     completion:^(BOOL finished){
                         NSLog(@"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height);
                     }];
     }
    else if (sender.direction ==  UISwipeGestureRecognizerDirectionDown) {

        NSLog(@"else if gesture up - PT");

        [UIView animateWithDuration:0.5
                              delay:0.1
                            options:UIViewAnimationOptionCurveEaseInOut
                         animations:^{
                             topContainerView.frame = CGRectMake(0.0, 0.0, 320.0, 244.0);
                             bottomContainerView.frame = CGRectMake(0.0, 244.0, self.view.frame.size.width, 216.0);
                         }
                         completion:^(BOOL finished){
                            NSLog(@"%f,%f",bottomContainerView.frame.size.width,bottomContainerView.frame.size.height); 
                         }];

    }
}        

}

POST UPDATED - 这是我的新代码,与您教给我的内容一致,请解释一下;-)

4

1 回答 1

0

看这段代码时,我的眼睛受伤了。

在这里,您尝试结合两种声明动画的方式。如果您正在使用beginAnimations:,则不必使用[UIView animateWithDuration:]方法,但必须使用完成动画代码[UIView commitAnimations];

最清晰的方法是使用[UIView animateWithDuration:]动画代码并将其放入animations:^{}块中。

PS:我强烈建议不要在代码中使用幻数,而是使用常量。SwitchToFullNormalScreen 和 SwitchToNormalScreen 动画只是复制粘贴。我的意思是来吧,那不好。

于 2013-07-07T03:25:34.860 回答