【发布时间】:2014-01-14 16:03:39
【问题描述】:
如何在滚动视图中单击按钮时进入情节提要的初始视图。
我的故事板包含以下内容:
[导航控制器] -> [TableView 控制器] -> [DetailView 控制器]
我的代码:
#import "AppDelegate.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window=[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
[self GuidePage];
return YES;
}
-(void)GuidePage
{
UIScrollView *scro=[[UIScrollView alloc]initWithFrame:self.window.bounds];
scro.pagingEnabled=YES;
_currentScro=scro;
scro.scrollEnabled=YES;
scro.bounces=NO;
scro.showsHorizontalScrollIndicator=NO;;
scro.delegate=self;
UIImageView *imgView1=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Guide1.png"]];
imgView1.frame=CGRectMake(0, 0, 320, 480);
UIImageView *imgView2=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Guide2.png"]];
imgView2.frame=CGRectMake(320, 0, 320, 480);
UIButton *btnEnter= [[UIButton alloc] initWithFrame:CGRectMake(400, 200, 100, 100)];
[btnEnter setTitle:@"Enter" forState:UIControlStateNormal];
[scro addSubview:imgView1];
[scro addSubview:imgView2];
[scro addSubview:btnEnter];
[btnEnter addTarget:self action:@selector(gotoMainStoryboard) forControlEvents:UIControlEventTouchUpInside];
scro.contentSize=CGSizeMake(320*2, scro.frame.size.height);
UIPageControl *page=[[UIPageControl alloc]initWithFrame:CGRectMake(0, 400, 320, 20)];
page.numberOfPages=2;
_pageControl=page;
[page addTarget:self action:@selector(changeCurrentPage:) forControlEvents:UIControlEventValueChanged];
page.backgroundColor=[UIColor redColor];
page.currentPage=0;
[self.window addSubview:scro];
[self.window addSubview:page];
}
-(void) gotoMainStoryboard
{
NSLog(@"goto");
}
-(void)changeCurrentPage:(UIPageControl *)sender
{
[_currentScro setContentOffset:CGPointMake(sender.currentPage*320, 0)];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if ((int)scrollView.contentOffset.x%320==0) {
_pageControl.currentPage=(int)scrollView.contentOffset.x/320;
}
}
@end
【问题讨论】:
标签: ios xcode storyboard