IOS- UIScrollview在目标C中滑动手势类似于Snapchat?

时间:2016-04-27 16:49:34

标签: ios objective-c uiscrollview

到目前为止我取得了什么成果?

1)我可以在视图控制器(View1和View 2)之间滑动,如下图所示

2)我在View1中创建了一个按钮,这样我就可以按下按钮进入View2。

Image 1

我想要实现的目标是什么?

1)通过从View1滑动到View2以及从View2滑动到View1,在这两个视图控制器(View1和View 2)之间进行A循环滑动。

2)按下View1中的按钮后,它会转到View2,之后我就不能再刷了。

感谢您对此问题的关注。感谢您的帮助

这是我的ScrollViewController.m代码

#import "ScrollViewController.h"
#import "View1.h"
#import "View2.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    View1 * V1 = [[View1 alloc]initWithNibName:@"View1" bundle:nil];
    View2 * V2 = [[View2 alloc]initWithNibName:@"View2" bundle:nil];



    [self addChildViewController:V1];
    [self.scrollView addSubview:V1.view];
    [V1 didMoveToParentViewController:self];


    [self addChildViewController:V2];
    [self.scrollView addSubview:V2.view];
    [V2 didMoveToParentViewController:self];

    CGRect V2Frame = V2.view.frame;
    V2Frame.origin.x= self.view.frame.size.width;
    V2.view.frame = V2Frame;

    self.scrollView.contentSize=CGSizeMake(self.view.frame.size.width * 2, self.view.frame.size.height);

}

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

@end

这是我的View1.m

的代码
#import "View1.h"
#import "View2.h"
#import "ViewController.h"

@interface View1 ()
@property (weak, nonatomic) IBOutlet UIScrollView *ScrollView;

@end

@implementation View1

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib

    }

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

- (IBAction)button:(id)sender {


    View2 * V2 = [[View2 alloc]initWithNibName:@"View2" bundle:nil];
    [self presentViewController:V2 animated:NO completion:NULL];


}

这里是我的代码For View2.m

#import "View2.h"
#import "View1.h"
#import "ViewController.h"

@interface View2 ()
@property (weak, nonatomic) IBOutlet UIScrollView *ScrollView;

@end

@implementation View2

- (void)viewDidLoad {
    [super viewDidLoad];

    // Do any additional setup after loading the view from its nib.




//self.ScrollView.contentSize=CGSizeMake(self.view.frame.size.width * 2, self.view.frame.size.height);
}

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

0 个答案:

没有答案