如何在 UIPageViewContoller 中滑动时移动 UIImageView

How to move UIImageView while swiping in UIPageViewContoller

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

在没有任何第三方的情况下尝试此代码Class 只需从库

添加 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

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)];
    }];

     }