Iphone 像google plus这样的视图切换
有没有像GooglePlus这样的视图开关之类的示例代码,在圆圈附近输入Iphone 像google plus这样的视图切换,iphone,objective-c,ios,Iphone,Objective C,Ios,有没有像GooglePlus这样的视图开关之类的示例代码,在圆圈附近输入 我做了这个,我想这和你想要的差不多 我做了这个,我想这和你想要的差不多 如果我正确理解您的问题,这将有所帮助。此处添加了标题2视图和动画,同时删除了标题1.view。您可以为右转换编写类似的代码 -(void)handleLeftTransition:(id)sender { if(![self.view.subviews containsObject:title2.view]) { titl
我做了这个,我想这和你想要的差不多
我做了这个,我想这和你想要的差不多
如果我正确理解您的问题,这将有所帮助。此处添加了标题2视图和动画,同时删除了标题1.view。您可以为右转换编写类似的代码
-(void)handleLeftTransition:(id)sender
{
if(![self.view.subviews containsObject:title2.view])
{
title2.view.frame = CGRectMake(320, 20, 320, 350);
[self.view addSubview:title2.view];
[UIView animateWithDuration:0.5f
animations:^{
title2.view.frame = CGRectMake(0, 20, 320, 350);
title1.view.frame = CGRectMake(-320, 20, 320, 350);
}
completion:^(BOOL finished){
if([self.view.subviews containsObject:title1.view])
[title1.view removeFromSuperview];
}];
}
}
如果我正确理解了你的问题,这将有所帮助。此处添加了标题2视图和动画,同时删除了标题1.view。您可以为右转换编写类似的代码
-(void)handleLeftTransition:(id)sender
{
if(![self.view.subviews containsObject:title2.view])
{
title2.view.frame = CGRectMake(320, 20, 320, 350);
[self.view addSubview:title2.view];
[UIView animateWithDuration:0.5f
animations:^{
title2.view.frame = CGRectMake(0, 20, 320, 350);
title1.view.frame = CGRectMake(-320, 20, 320, 350);
}
completion:^(BOOL finished){
if([self.view.subviews containsObject:title1.view])
[title1.view removeFromSuperview];
}];
}
}
@Hubert我已经对你的代码做了一些调整,现在你可以滚动topScrollView并移动bottomScrollView。代码在这里
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView == self.bottomScrollView) {
//i dont know where this number came from 2.46153846
float bOffset = self.bottomScrollView.contentOffset.x/2.66666666666667;
NSLog(@"%f",self.bottomScrollView.contentOffset.x);
NSLog(@"%f",self.topScrollView.contentOffset.x);
CGPoint theOffset = CGPointMake(self.bottomScrollView.contentOffset.x, self.topScrollView.contentOffset.y);
theOffset.x = bOffset;
[self.topScrollView setContentOffset:theOffset animated:NO];
}
// if the TopScrollView is Moved
if (scrollView == self.topScrollView) {
float bOffset = self.topScrollView.contentOffset.x*2.66666666666667;
CGPoint theOffset = CGPointMake(self.topScrollView.contentOffset.x, self.bottomScrollView.contentOffset.y);
theOffset.x = bOffset;
[self.bottomScrollView setContentOffset:theOffset animated:NO];
}
}@Hubert我已经对代码做了一些调整,现在您可以滚动topScrollView并移动底部ScrollView。代码在这里
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView == self.bottomScrollView) {
//i dont know where this number came from 2.46153846
float bOffset = self.bottomScrollView.contentOffset.x/2.66666666666667;
NSLog(@"%f",self.bottomScrollView.contentOffset.x);
NSLog(@"%f",self.topScrollView.contentOffset.x);
CGPoint theOffset = CGPointMake(self.bottomScrollView.contentOffset.x, self.topScrollView.contentOffset.y);
theOffset.x = bOffset;
[self.topScrollView setContentOffset:theOffset animated:NO];
}
// if the TopScrollView is Moved
if (scrollView == self.topScrollView) {
float bOffset = self.topScrollView.contentOffset.x*2.66666666666667;
CGPoint theOffset = CGPointMake(self.topScrollView.contentOffset.x, self.bottomScrollView.contentOffset.y);
theOffset.x = bOffset;
[self.bottomScrollView setContentOffset:theOffset animated:NO];
}
}是你在找的东西吗?是你在找的东西吗?@Alex 2.666667从哪里来?哦,那是我的错。。。如果我没有错。。。这是scrollview的大小除以视图大小之类的东西。。。但这是错误的。。。正确的号码是2.46153846。。。对不起that@Alex2.66666667从哪里来?哦,那是我的错。。。如果我没有错。。。这是scrollview的大小除以视图大小之类的东西。。。但这是错误的。。。正确的号码是2.46153846。。。对不起