在连接到iPad的外部屏幕上滚动UIScrollView
嘿。我已经通过缩放实现了编程的UIScrollView,但现在我一直在尝试将可滚动/可缩放的图像插入外部屏幕(如果插入)在连接到iPad的外部屏幕上滚动UIScrollView,ipad,uiscrollview,screen,external,television,Ipad,Uiscrollview,Screen,External,Television,嘿。我已经通过缩放实现了编程的UIScrollView,但现在我一直在尝试将可滚动/可缩放的图像插入外部屏幕(如果插入) @implementation MapVC UIScrollView *mapScrollView; UIImageView *mapImageView; UIImageView *mapImageViewEx; CGFloat lastScale = 0; NSMutableArray *map_List; - (id)initWithFrame:(CGRec
@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;
}
}
@实现MapVC
UIScrollView*地图滚动视图;
UIImageView*mapImageView;
UIImageView*mapImageViewEx;
CGFloat lastScale=0;
NSMutableArray*映射列表;
-(id)initWithFrame:(CGRect)帧{
self=[super initWithFrame:frame];
如果(自我){
mainMenuAppDelegate*del=(mainMenuAppDelegate*)[[UIApplication sharedApplication]委托];
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)self];
mapScrollView.contentSize=CGSizeMake(24371536);
mapScrollView.bounces=否;
mapScrollView.bouncesZoom=否;
mapScrollView.minimumZoomScale=.5;
mapScrollView.maximumZoomScale=1.5;
[mapScrollView设置缩放比例:mapScrollView.minimumZoomScale];
UIImage*mapImage=[UIImage ImageName:[map_列表对象索引:mapNum]];
mapImageView=[[UIImageView alloc]initWithImage:mapImage];
[地图图像发布];
如果(exScreenEnabled==1){
UIImage*mapImageEx=[UIImage ImageName:[map_列表对象索引:mapNum]];
mapImageViewEx=[[UIImageView alloc]initWithImage:mapImageEx];
[MAPIMAGEX释放];
UIView*ContainerXViewp=(UIView*)[del.switchExVC.view-viewWithTag:9000];
[ContainerExView addSubview:mapImageViewEx];
}否则{
[mapScrollView添加子视图:mapImageView];
}
[自添加子视图:mapScrollView];
mapImageView.userInteractionEnabled=是;
UIImage*footerMapIMG=[UIImage ImageName:@“footer\u map\u alternate.png”];
UIImageView*footerMapView=[[UIImageView alloc]initWithImage:(UIImage*)footerMapIMG];
CGRect footerMapFrame=CGRectMake(0686213,82);
footerMapView.frame=footerMapFrame;
[自添加子视图:footerMapView];
footerMapView.image=footerMapIMG;
[footerMapView发布];
CGRect backBTNFrame=CGRectMake(20714,140,52);
UIButton*MAP_backButton=[[UIButton alloc]init];
MAP_backButton.frame=backBTNFrame;
UIImage*MAP_backButtonIMG=[UIImage ImageName:@“button_back.png”];
[MAP_backButton setImage:MAP_backButtonIMG for state:UIControlStateNormal];
MAP_backButton.backgroundColor=[UIColor clearColor];
[自添加子视图:映射返回按钮];
[MAP_backButton release];
[MAP_backButton addTarget:del.switchVC
操作:@选择器(GoToMandListChooser)
forControlEvents:UIControlEventTouchUpInside];
}
回归自我;
}
-(UIView*)视图用于缩放CrollView:(UICrollView*)滚动视图{
如果(exScreenEnabled==1){
返回mapImageViewEx;
}否则{
返回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
@实现MapVC
UIScrollView*地图滚动视图;
UIImageView*mapImageView;
UIImageView*mapImageViewEx;
CGFloat lastScale=0;
NSMutableArray*映射列表;
int touchesNum=0;
-(无效)触摸开始:(NSSet*)触摸带事件:(UIEvent*)事件{
NSSet*touchs=[event alltouchs];
touchesNum=[触摸次数];
NSLog(@“触摸次数%i”,touchesNum);
}
-(id)initWithFrame:(CGRect)帧{
self=[super initWithFrame:frame];
如果(自我){
mainMenuAppDelegate*del=(mainMenuAppDelegate*)[[UIApplication sharedApplication]委托];
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)self];
mapScrollView.contentSize=CGSizeMake(24371536);
mapScrollView.bounces=否;
mapScrollView.bouncesZoom=否;
mapScrollView.minimumZoomScale=.5;
mapScrollView.maximumZoomScale=1.5;
[mapScrollView设置缩放比例:mapScrollView.minimumZoomScale];
UIImage*mapImage=[UIImage ImageName:[map_列表对象索引:mapNum]];
mapImageView=[[UIImageView alloc]initWithImage:mapImage];
[地图图像发布];
如果(exScreenEnabled==1){
UIImage*mapImageEx=[UIImage ImageName:[map_列表对象索引:mapNum]];
mapImageViewEx=[[UIImageView alloc]initWithImage:mapImageEx];
[MAPIMAGEX释放];
UIView*ContainerXViewp=(UIView*)[del.switchExVC.view-viewWithTag:9000];
[ContainerExView addSubview:mapImageViewEx];
}否则{
[mapScrollView添加子视图:mapImageView];
}
[自添加子视图:mapScrollView];
mapImageView.userInteractionEnabled=是;
UIImage*footerMapIMG=[UIImage ImageName:@“footer\u map\u alternate.png”];
UIImageView*footerMapView=[[UIImageView alloc]initWithImage:(UIImage*)footerMapIMG];
CGRect footerMapFrame=CGRectMake(0686213,82);
footerMapView.frame=footerMapFrame;
[自添加子视图:footerMapView];
#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