如何在UIPageViewContoller

时间:2016-02-01 01:19:31

标签: ios objective-c uiimageview uipageviewcontroller ios-animations

当用户滑动应用简介时,我想慢慢移动red circle(如下图所示)(可能带动画)( PageViewController ) 。我还想添加一些动画,因此我尝试使用IFTTT/JazzHands framework。但目前我很难理解。有没有简单的方法在PageViewController中使用动画?或者是否有任何使用IFTTT/JazzHands框架的教程?请问有人帮帮我吗?

enter image description here

2 个答案:

答案 0 :(得分:1)

Try this if its is ok vote for me


@interface homeViewController ()<UIScrollViewDelegate>

@property (weak, nonatomic) IBOutlet UIScrollView *scrollViewSlider;

@end

@implementation homeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBarHidden=true;
    [NSTimer scheduledTimerWithTimeInterval:4 target:self
    selector:@selector(scrollingTimer) userInfo:nil repeats:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


-(void)viewDidLayoutSubviews
{
    UIImage *imageOne = [UIImage imageNamed:@"download.jpeg"];
    UIImage *imageTwo = [UIImage imageNamed:@"download2.jpeg"];
    UIImage *imageThree = [UIImage imageNamed:@"download3.jpeg"];
    UIImage *imageFour = [UIImage imageNamed:@"download4.jpeg"];

    NSArray *imageArray = [NSArray arrayWithObjects:imageOne,
                        imageTwo, imageThree, imageFour, nil];

    for (int i = 0; i <= 3; i++) {

        UIImageView *imgView = [[UIImageView alloc]init];
        imgView.contentMode = UIViewContentModeScaleToFill;
        imgView.alpha = 0.5f;
        imgView.frame = CGRectMake(i * self.scrollViewSlider.bounds.size.width,
                                    0, self.scrollViewSlider.bounds.size.width,
                                   self.scrollViewSlider.bounds.size.height);

        [imgView setImage:imageArray[i]];
        [self.scrollViewSlider addSubview:imgView];
        self.scrollViewSlider.pagingEnabled = true;

        [self.scrollViewSlider setContentSize:CGSizeMake(imageArray.count *
                                                                                                       self.scrollViewSlider.bounds.size.width,
                                                         self.scrollViewSlider.bounds.size.height-20)];


    }
}

-(void) scrollingTimer
{
    CGPoint frame =  self.scrollViewSlider.contentOffset;
    [UIView animateWithDuration:3.0f animations:^(void) {

        if (frame.x != 3 * self.scrollViewSlider.frame.size.width)

            [self.scrollViewSlider setContentOffset:CGPointMake(frame.x +

                                                            self.scrollViewSlider.frame.size.width, 0)];
        else

            [self.scrollViewSlider setContentOffset:CGPointMake(0, 0)];
    }];

     }

答案 1 :(得分:0)

在没有任何第三方类的情况下试用此代码 只需从库中添加QuartzCore framwork

#import <QuartzCore/QuartzCore.h>

- (CAAnimation*)movedown;
    {
        CABasicAnimation *animation = [CABasicAnimation animation];
        animation.keyPath = @"position.y";
        animation.fromValue = @600;
        animation.toValue = @50;
        animation.duration = 0.25;

        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

        [subView.layer addAnimation:animation forKey:@"basic"];    
        subView.layer.position = CGPointMake(0,-20);
        return animation;
    }

请替换subview的动画视图。