2011-02-08 9 views
1

ねえ。私はズームと、プログラムUIScrollViewのを作っ達成したが、今私が差し込まれている場合、外部の画面にスクロール/ズーム可能な画像を撮影しようとしてきた。iPadに接続された外部スクリーン上のスクロールUIScrollView

@implementation MapVC 

UIScrollView *mapScrollView; 

UIImageView *mapImageView; 

UIImageView *mapImageViewEx; 

CGFloat lastScale = 0; 

NSMutableArray *map_List; 


- (id)initWithFrame:(CGRect)frame { 

    self = [super initWithFrame:frame]; 
    if (self) { 

     mainMenuAppDelegate *del = (mainMenuAppDelegate *)[[UIApplication sharedApplication] delegate]; 

     map_List = [[NSMutableArray alloc] init]; 
     [map_List addObject:@"Pacific_Map.png"]; 
     [map_List addObject:@"Atlantic_Map.png"]; 


     CGRect mapScrollViewFrame = CGRectMake(0, 0, 1024, 768); 

     mapScrollView = [[UIScrollView alloc] initWithFrame:mapScrollViewFrame]; 

     mapScrollView.backgroundColor = [UIColor blackColor]; 

     [mapScrollView setDelegate:(id<UIScrollViewDelegate>)self]; 

     mapScrollView.contentSize = CGSizeMake(2437, 1536); 

     mapScrollView.bounces = NO; 

     mapScrollView.bouncesZoom = NO; 

     mapScrollView.minimumZoomScale = .5; 

     mapScrollView.maximumZoomScale = 1.5; 

     [mapScrollView setZoomScale:mapScrollView.minimumZoomScale]; 

     UIImage *mapImage = [UIImage imageNamed:[map_List objectAtIndex:mapNum]]; 
     mapImageView = [[UIImageView alloc] initWithImage: mapImage]; 
     [mapImage release]; 

     if(exScreenEnabled==1){ 
      UIImage *mapImageEx = [UIImage imageNamed:[map_List objectAtIndex:mapNum]]; 
      mapImageViewEx = [[UIImageView alloc] initWithImage: mapImageEx]; 
      [mapImageEx release]; 

      UIView *containerExViewP = (UIView*)[del.switchExVC.view viewWithTag:9000]; 
      [containerExViewP addSubview:mapImageViewEx]; 
     }else{ 
      [mapScrollView addSubview:mapImageView]; 
     } 



     [self addSubview:mapScrollView]; 

     mapImageView.userInteractionEnabled = YES; 



     UIImage *footerMapIMG = [UIImage imageNamed:@"footer_map_alternate.png"]; 
     UIImageView *footerMapView = [[UIImageView alloc] initWithImage:(UIImage *)footerMapIMG]; 
     CGRect footerMapFrame = CGRectMake(0, 686, 213, 82); 
     footerMapView.frame = footerMapFrame; 
     [self addSubview:footerMapView]; 
     footerMapView.image = footerMapIMG; 

     [footerMapView release]; 


     CGRect backBTNFrame = CGRectMake(20, 714, 140, 52); 
     UIButton *MAP_backButton = [[UIButton alloc] init]; 
     MAP_backButton.frame = backBTNFrame; 
     UIImage *MAP_backButtonIMG = [UIImage imageNamed:@"button_back.png"]; 
     [MAP_backButton setImage:MAP_backButtonIMG forState:UIControlStateNormal]; 
     MAP_backButton.backgroundColor = [UIColor clearColor]; 
     [self addSubview:MAP_backButton]; 

     [MAP_backButton release]; 


     [MAP_backButton addTarget:del.switchVC 
          action:@selector(gotoMapAndListChooser) 
         forControlEvents:UIControlEventTouchUpInside]; 
    } 
    return self; 
} 
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{ 
    if(exScreenEnabled==1){ 
     return mapImageViewEx; 
    }else{ 
     return mapImageView; 
    } 
} 

(申し訳ありませんが、私はそれを取得運がなかったしました

ビデオケーブルがiPadに差し込まれている場合、iPadにはイメージがありません。これは私が望むものです。 iPad上でジェスチャーを行うと、外部画面の画像が正しくズームされますが、スクロールする方法を理解することはできません。前もって感謝します。

編集:私は今、この持っている - 私は以下の言ったように、私は今のいずれかを取得スクロールしたり、別々に動作するようにズームすることができます

@implementation MapVC 

UIScrollView *mapScrollView; 

UIImageView *mapImageView; 
UIImageView *mapImageViewEx; 

CGFloat lastScale = 0; 

NSMutableArray *map_List; 

int touchesNum = 0; 

-(void)touchesBegan:(NSSet *)theTouches withEvent:(UIEvent *)event { 
    NSSet *touches = [event allTouches]; 
    touchesNum=[touches count]; 
    NSLog(@"number of touches %i", touchesNum); 
} 


- (id)initWithFrame:(CGRect)frame { 

    self = [super initWithFrame:frame]; 
    if (self) { 



     mainMenuAppDelegate *del = (mainMenuAppDelegate *)[[UIApplication sharedApplication] delegate]; 

     map_List = [[NSMutableArray alloc] init]; 
     [map_List addObject:@"Pacific_Map.png"]; 
     [map_List addObject:@"Atlantic_Map.png"]; 


     CGRect mapScrollViewFrame = CGRectMake(0, 0, 1024, 768); 

     mapScrollView = [[UIScrollView alloc] initWithFrame:mapScrollViewFrame]; 

     mapScrollView.backgroundColor = [UIColor blackColor]; 

     [mapScrollView setDelegate:(id<UIScrollViewDelegate>)self]; 

     mapScrollView.contentSize = CGSizeMake(2437, 1536); 

     mapScrollView.bounces = NO; 

     mapScrollView.bouncesZoom = NO; 

     mapScrollView.minimumZoomScale = .5; 

     mapScrollView.maximumZoomScale = 1.5; 

     [mapScrollView setZoomScale:mapScrollView.minimumZoomScale]; 

     UIImage *mapImage = [UIImage imageNamed:[map_List objectAtIndex:mapNum]]; 
     mapImageView = [[UIImageView alloc] initWithImage: mapImage]; 
     [mapImage release]; 

     if(exScreenEnabled==1){ 
      UIImage *mapImageEx = [UIImage imageNamed:[map_List objectAtIndex:mapNum]]; 
      mapImageViewEx = [[UIImageView alloc] initWithImage: mapImageEx]; 
      [mapImageEx release]; 

      UIView *containerExViewP = (UIView*)[del.switchExVC.view viewWithTag:9000]; 
      [containerExViewP addSubview:mapImageViewEx]; 
     }else{ 
      [mapScrollView addSubview:mapImageView]; 
     } 



     [self addSubview:mapScrollView]; 

     mapImageView.userInteractionEnabled = YES; 



     UIImage *footerMapIMG = [UIImage imageNamed:@"footer_map_alternate.png"]; 
     UIImageView *footerMapView = [[UIImageView alloc] initWithImage:(UIImage *)footerMapIMG]; 
     CGRect footerMapFrame = CGRectMake(0, 686, 213, 82); 
     footerMapView.frame = footerMapFrame; 
     [self addSubview:footerMapView]; 
     footerMapView.image = footerMapIMG; 

     [footerMapView release]; 


     CGRect backBTNFrame = CGRectMake(20, 714, 140, 52); 
     UIButton *MAP_backButton = [[UIButton alloc] init]; 
     MAP_backButton.frame = backBTNFrame; 
     UIImage *MAP_backButtonIMG = [UIImage imageNamed:@"button_back.png"]; 
     [MAP_backButton setImage:MAP_backButtonIMG forState:UIControlStateNormal]; 
     MAP_backButton.backgroundColor = [UIColor clearColor]; 
     [self addSubview:MAP_backButton]; 

     [MAP_backButton release]; 


     [MAP_backButton addTarget:del.switchVC 
          action:@selector(gotoMapAndListChooser) 
         forControlEvents:UIControlEventTouchUpInside]; 

     mapScrollView.multipleTouchEnabled = YES; 
    } 
    return self; 
} 


- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{ 
    if(exScreenEnabled==1){ 
     return mapImageViewEx; 
    }else{ 
     return mapImageView; 
    } 
} 

- (void)scrollViewDidScroll:(UIScrollView *)inscrollView{ 
    if(touchesNum==0){ 
     CGPoint p = mapScrollView.contentOffset; 
     mapImageViewEx.frame = CGRectMake((p.x*-1), (p.y*-1), mapImageViewEx.frame.size.width, mapImageViewEx.frame.size.height); 
    } 
} 



- (void)dealloc { 

    [mapScrollView release]; 
    [mapImageView release]; 

    [map_List release]; 


    [super dealloc]; 
} 

@end 

を、しかしときのでスクロールが、作業している場合、ズームは全て台無しにされましたズームすると、それもスクロールしていると考えられます。だから私はズームを避けるために、それを避けたい、そしてこれを行うには、私は間違っていなければならないタッチの数を検出したい!

+0

私は、コンテンツのオフセットhttp://forums.macrumors.com/showthread.php?t=568315を使用して、その座標を他の画面の画像に設定して運がよいかもしれません。 – VagueExplanation

+0

私は今scrollViewDidScrollでスクロールし、座標を外部スクリーンに渡すようにしています。問題は、ズームとスクロールの両方の作業を同時に行うことができないことです。ズームが問題になるためです。私が考えた解決策は、タッチが何回起こっているのかを検出することでしたが、開始されたタッチはNSLog.Grrに何も表示されませんでした – VagueExplanation

答えて

1

iPadと外付けスクリーンに画像が表示されています。私は多分画像がiPadと外部スクリーンの両方に重く重いので、おそらく長方形の領域でそれを交換します。

#import "exGlobal.h" 

#import "mapVC.h" 

#import "switchVC.h" 
#import "switchExVC.h" 
#import "mainMenuAppDelegate.h" 


#import <MobileCoreServices/MobileCoreServices.h> 

@implementation MapVC 

UIScrollView *mapScrollView; 

UIImageView *mapImageView; 
UIImageView *mapImageViewEx; 

CGFloat lastScale = 0; 

NSMutableArray *map_List; 

static int toggleScroll = 1; 


- (id)initWithFrame:(CGRect)frame { 

    self = [super initWithFrame:frame]; 
    if (self) { 

     mainMenuAppDelegate *del = (mainMenuAppDelegate *)[[UIApplication sharedApplication] delegate]; 

     map_List = [[NSMutableArray alloc] init]; 
     [map_List addObject:@"Pacific_Map.png"]; 
     [map_List addObject:@"Atlantic_Map.png"]; 


     CGRect mapScrollViewFrame = CGRectMake(0, 0, 1024, 768); 

     mapScrollView = [[UIScrollView alloc] initWithFrame:mapScrollViewFrame]; 

     mapScrollView.backgroundColor = [UIColor blackColor]; 

     [mapScrollView setDelegate:(id<UIScrollViewDelegate>)self]; 

     mapScrollView.contentSize = CGSizeMake(2437, 1536); 

     mapScrollView.bounces = NO; 

     mapScrollView.bouncesZoom = NO; 

     mapScrollView.minimumZoomScale = .5; 

     mapScrollView.maximumZoomScale = 1.5; 

     [mapScrollView setZoomScale:mapScrollView.minimumZoomScale]; 

     UIImage *mapImage = [UIImage imageNamed:[map_List objectAtIndex:mapNum]]; 
     mapImageView = [[UIImageView alloc] initWithImage: mapImage]; 
     [mapImage release]; 

     if(exScreenEnabled==1){ 
      UIImage *mapImageEx = [UIImage imageNamed:[map_List objectAtIndex:mapNum]]; 
      mapImageViewEx = [[UIImageView alloc] initWithImage: mapImageEx]; 
      [mapImageEx release]; 

      UIView *containerExViewP = (UIView*)[del.switchExVC.view viewWithTag:9000]; 
      [containerExViewP addSubview:mapImageViewEx]; 
      [mapScrollView addSubview:mapImageView]; // see if this works ok on iPad. Map on TV AND iPad. 
     }else{ 
      [mapScrollView addSubview:mapImageView]; 
     } 

     [self addSubview:mapScrollView]; 

     mapImageView.userInteractionEnabled = YES; 


     UIImage *footerMapIMG = [UIImage imageNamed:@"footer_map_alternate.png"]; 
     UIImageView *footerMapView = [[UIImageView alloc] initWithImage:(UIImage *)footerMapIMG]; 
     CGRect footerMapFrame = CGRectMake(0, 686, 213, 82); 
     footerMapView.frame = footerMapFrame; 
     [self addSubview:footerMapView]; 
     footerMapView.image = footerMapIMG; 

     [footerMapView release]; 


     CGRect backBTNFrame = CGRectMake(20, 714, 140, 52); 
     UIButton *MAP_backButton = [[UIButton alloc] init]; 
     MAP_backButton.frame = backBTNFrame; 
     UIImage *MAP_backButtonIMG = [UIImage imageNamed:@"button_back.png"]; 
     [MAP_backButton setImage:MAP_backButtonIMG forState:UIControlStateNormal]; 
     MAP_backButton.backgroundColor = [UIColor clearColor]; 
     [self addSubview:MAP_backButton]; 

     [MAP_backButton release]; 


     [MAP_backButton addTarget:del.switchVC 
          action:@selector(gotoMapAndListChooser) 
         forControlEvents:UIControlEventTouchUpInside]; 

     mapScrollView.multipleTouchEnabled = YES; 
    } 
    return self; 
} 


- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{ 
    return mapImageView; 
} 

-(void)scrollViewDidZoom:(UIScrollView *)scrollView { 
    if(exScreenEnabled==1){ 
     CGPoint p = mapScrollView.contentOffset; 
     mapImageViewEx.frame = CGRectMake((p.x*-1), (p.y*-1), mapImageView.frame.size.width, mapImageView.frame.size.height); 
    } 
} 

- (void)scrollViewDidScroll:(UIScrollView *)inscrollView{ 
    if(exScreenEnabled==1 && toggleScroll==1){ 
     CGPoint p = mapScrollView.contentOffset; 
     mapImageViewEx.frame = CGRectMake((p.x*-1), (p.y*-1), mapImageView.frame.size.width, mapImageView.frame.size.height); 

    } 
} 

- (void)scrollViewWillBeginZooming:(UIScrollView *)theScrollView withView:(UIView *)view{ 
    NSLog(@"BEGIN ZOOMING"); 
    toggleScroll=0; 
} 

- (void)scrollViewDidEndZooming:(UIScrollView *)theScrollView withView:(UIView *)view atScale:(float)scale{ 
    NSLog(@"END ZOOMING"); 
    toggleScroll=1; 
} 




- (void)dealloc { 

    [mapScrollView release]; 
    [mapImageView release]; 

    [map_List release]; 

    [super dealloc]; 
} 

@end 

コードのスペースバー(4)を押しても、NOPEが機能しないため、スタックオーバーフローが依然として壊れています。 :)

+1

_every_コード行の前に4スペースを入れなければなりません。しかし、コードを強調表示して '{}'ボタンを押すほうがはるかに簡単です。 – Anna

+0

次回は{}ボタンを探します。 – VagueExplanation

関連する問題