2012-07-31 38 views
0

如何在iOS中添加頁面控件UIScrollViewUIImageView。如果我選擇了某些頁面控件項目符號,意味着我想要移動選定的圖像。如果我移動圖像意味着我的pagecontrol項目符號也希望在UIScrollView中移動。如何在iOS中爲UIScrollview添加UIImageview的頁面控件

- (void)viewDidLoad 
{ 
    NSLog(@"Welcome to Home Page"); 
    [super viewDidLoad]; 

    // self.view.backgroundColor=[[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"bg-image.png"]]; 

    UIImage * img = [UIImage imageNamed:@"bg-image.png"]; 
    [scrollView setBackgroundColor:[UIColor colorWithPatternImage:img]]; 
// Do any additional setup after loading the view, typically from a nib. 
} 



- (void)loadView { 


    CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame]; 
    scrollView=[[UIScrollView alloc] initWithFrame:fullScreenRect]; 
    scrollView.contentSize=CGSizeMake(1400, 100); 

    UIImageView *tempImageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sti01.png"]]; 
    tempImageView2.frame=CGRectMake(10, 60, 200, 200); 
    [scrollView addSubview:tempImageView2]; 


    UIImageView *tempImageView3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sti02.png"]]; 
    tempImageView3.frame=CGRectMake(240, 60, 200, 200); 
    [scrollView addSubview:tempImageView3]; 

    UIImageView *tempImageView4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sti03.png"]]; 
    tempImageView4.frame=CGRectMake(470, 60, 200, 200); 
    [scrollView addSubview:tempImageView4]; 

    UIImageView *tempImageView5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sti04.png"]]; 
    tempImageView5.frame=CGRectMake(700, 60, 200, 200); 
    [scrollView addSubview:tempImageView5]; 


    UIImageView *tempImageView6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sti05.png"]]; 
    tempImageView6.frame=CGRectMake(930, 60, 200, 200); 
    [scrollView addSubview:tempImageView6]; 

    UIImageView *tempImageView7 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sti06.png"]]; 
    tempImageView7.frame=CGRectMake(1160, 60, 200, 200); 
    [scrollView addSubview:tempImageView7]; 



    self.view=scrollView; 
    [scrollView addSubview:tempImageView2]; 
    [scrollView addSubview:tempImageView3]; 
    [scrollView addSubview:tempImageView4]; 
    [scrollView addSubview:tempImageView5]; 
    [scrollView addSubview:tempImageView6]; 
    [scrollView addSubview:tempImageView7]; 

    scrollView.userInteractionEnabled = YES; 
    btn = [UIButton buttonWithType:UIButtonTypeCustom]; 
    btn.frame = CGRectMake(22, 100, 1800, 500); 
    // [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
    [btn addTarget:self action:@selector(buttonTest:) forControlEvents:UIControlEventTouchUpInside];  
    [scrollView addSubview:btn]; 


} 


- (IBAction)buttonTest:(id)sender { 
    MSDescriptionpage *aSecondPageController = [[MSDescriptionpage alloc] initWithNibName:@"MSDescriptionpage" bundle:nil];   
    [self.navigationController pushViewController:aSecondPageController animated:YES];   
    [aSecondPageController release]; 

} 
+0

http://www.raywenderlich.com/10518/how-to-use-uiscrollview-to-scroll-and-zoom-content – NIKHIL 2012-07-31 05:38:28

+0

這是iphone.But我想爲ipad做。 – User123 2012-07-31 05:56:42

+0

嗨nikhil這個代碼如何使用uibutton動態傳遞圖像到下一頁... – User123 2012-07-31 05:57:27

回答

0

我不得不這樣做,我所做的是我用了兩個視圖控制器(用於頁面刷卡頁面視圖控制器)和主視圖控制器與UIImage意見,並可以與此圖像添加滾動視圖.. 這些頁面VC 內做負載

[pageController setViewControllers:viewControllers 
          direction:UIPageViewControllerNavigationDirectionReverse 
           animated:NO 
          completion:nil]; 

    [self addChildViewController:pageController]; 
    [[self view] addSubview:[pageController view]]; 
    for (UIGestureRecognizer *gR in pageController.gestureRecognizers) { 
     gR.delegate = self; 
    } 
    [pageController didMoveToParentViewController:self];} 

這些調用另一個VC

- (UIViewController *)pageViewController: 
(UIPageViewController *)pageViewController viewControllerBeforeViewController: 
(UIViewController *)viewController 
{ 
    for (UIGestureRecognizer *recognizer in pageController.gestureRecognizers) { 
     if ([recognizer isKindOfClass:[UITapGestureRecognizer class]]) { 
      recognizer.enabled = NO; 
     } 
    } 
    NSUInteger index = [self indexOfViewController: 
         (MainViewController *)viewController]; 
    if ((index == 0) || (index == NSNotFound)) { 
     return nil; 
    } 

    index--; 
    return [self viewControllerAtIndex:index]; 
} 
+0

好的,謝謝我現在就試試。 – User123 2012-07-31 07:51:30

+0

好的,如果這是有幫助的,你可以投票了..如果你的問題解決了,你可以檢查我的答案正確.. – iMeMyself 2012-07-31 08:41:05

相關問題