如何在iOs中从右侧到左侧显示视图?

时间:2016-05-16 05:29:51

标签: ios objective-c

视图不在屏幕上,我知道如何从左到右制作视图,但相反,我不确定视图的原始坐标是什么来自右边

rightImage = [[UIImageView alloc]init];
rightImage.size = CGSizeMake(kScreenWidth*5/9, kScreenHeight*5/12);
CGPoint rightImageCenter = rightImage.center;
rightImageCenter.x += kScreenWidth + 100;
rightImageCenter.y = kScreenHeight * 0.6;
rightImage.center = rightImageCenter;


[UIView animateWithDuration:0.3 animations:^{
        rightCenter.x -= 200;
        rightCenter.y += kScreenHeight*0.6;
        UIImage *image=[UIImage imageNamed:@"pic.png"];
        rightImage.image=image;
        rightImage.center = rightCenter;
        label.text = arr[1];
 } completion:nil];

1 个答案:

答案 0 :(得分:0)

我在一个案例中所做的是,

从右到左显示

-(void)viewDidAppear:(BOOL)animated{

 // [self.view setBackgroundColor:[UIColor clearColor]];
[self.view layoutIfNeeded];  // I am using autolayout!
[UIView animateWithDuration:0.3f
                 animations:^ {


                     CGRect frame = self.sideMenu.frame;
                     frame.origin.x = myX;
                     self.sideMenu.frame = frame;
                     self.sideMenu.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0);

                 }
                 completion:^(BOOL finished) {

// [UIView beginAnimations:nil context:nil];
// [UIView setAnimationDuration:5.3];
// [UIView commitAnimations];
                 }];




}

当它消失时,如下所示,

- (IBAction)sideMenuClick:(id)sender {

[UIView animateWithDuration:0.3f
                 animations:^ {
                     CGRect frame = self.sideMenu.frame;
                     frame.origin.x = self.view.frame.size.width;
                     self.sideMenu.frame = frame;
                     self.sideMenu.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0);
                 }
                 completion:^(BOOL finished) {

                     //                         [UIView beginAnimations:nil context:nil];
                     //                         [UIView setAnimationDuration:5.3];
                     //                         [UIView commitAnimations];
                     [self dismissViewControllerAnimated:NO completion:nil];
                 }];

 }

避免注释代码!!

此处side menuUIView,从右向左移动。

myX应计入viewDidload

   myX = self.view.frame.size.width - self.sideMenu.frame.size.width;

side menu的初始位置(表示x =屏幕宽度,即self.view.frame.size.width)。

您可以根据自己的需要管理您的方案,就像我在我的案例中所做的那样

希望这会有所帮助:)