Losing Gesture Recognizers in UIPopoverController - objective-c

I have a class called PhotoBoothController that I use to manipulate an image using gestures. It works fine when I run it on iPhone. However when I run it on iPad, I display the PhotoBoothController inside a UIPopoverController. The image appears fine, however I can't manipulate it as my gestures don't appear to be recognized. I'm not sure how to make the UIPopoverController take control of the gestures.
I present the popovercontroller and configure the view thus:
- (void)presentPhotoBoothForPhoto:(UIImage *)photo button:(UIButton *)button {
//Create a photoBooth and set its contents
PhotoBoothController *photoBoothController = [[PhotoBoothController alloc] init];
photoBoothController.photoImage.image = [button backgroundImageForState:UIControlStateNormal];
//set up all the elements programmatically.
photoBoothController.view.backgroundColor = [UIColor whiteColor];
//Add frame (static)
UIImage *frame = [[UIImage imageNamed:#"HumptyLine1Frame.png"] adjustForResolution];
UIImageView *frameView = [[UIImageView alloc] initWithImage:frame];
frameView.frame = CGRectMake(50, 50, frame.size.width, frame.size.height);
[photoBoothController.view addSubview:frameView];
//Configure image
UIImageView *photoView = [[UIImageView alloc] initWithImage:photo];
photoView.frame = CGRectMake(50, 50, photo.size.width, photo.size.height);
photoBoothController.photoImage = photoView;
//Add canvas
UIView *canvas = [[UIView alloc] initWithFrame:frameView.frame];
photoBoothController.canvas = canvas;
[canvas addSubview:photoView];
[canvas becomeFirstResponder];
[photoBoothController.view addSubview:canvas];
[photoBoothController.view bringSubviewToFront:frameView];
//resize the popover view shown in the current view to the view's size
photoBoothController.contentSizeForViewInPopover = CGSizeMake(frameView.frame.size.width+100, frameView.frame.size.height+400);
self.photoBooth = [[UIPopoverController alloc] initWithContentViewController:photoBoothController];
[self.photoBooth presentPopoverFromRect:button.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
I thought [canvas becomeFirstResponder] might do it but it doesn't appear to make a difference.
Any advice much appreciate, thank you.
UPDATE: adding code as per comment
- (void)viewDidLoad {
[super viewDidLoad];
if (!_marque) {
_marque = [CAShapeLayer layer];
_marque.fillColor = [[UIColor clearColor] CGColor];
_marque.strokeColor = [[UIColor grayColor] CGColor];
_marque.lineWidth = 1.0f;
_marque.lineJoin = kCALineJoinRound;
_marque.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInt:10],[NSNumber numberWithInt:5], nil];
_marque.bounds = CGRectMake(photoImage.frame.origin.x, photoImage.frame.origin.y, 0, 0);
_marque.position = CGPointMake(photoImage.frame.origin.x + canvas.frame.origin.x, photoImage.frame.origin.y + canvas.frame.origin.y);
}
[[self.view layer] addSublayer:_marque];
UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:#selector(scale:)];
[pinchRecognizer setDelegate:self];
[self.view addGestureRecognizer:pinchRecognizer];
UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:#selector(rotate:)];
[rotationRecognizer setDelegate:self];
[self.view addGestureRecognizer:rotationRecognizer];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(move:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[canvas addGestureRecognizer:panRecognizer];
UITapGestureRecognizer *tapProfileImageRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapped:)];
[tapProfileImageRecognizer setNumberOfTapsRequired:1];
[tapProfileImageRecognizer setDelegate:self];
[canvas addGestureRecognizer:tapProfileImageRecognizer];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return ![gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && ![gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]];
}

I am working on a similar application, and i can easily manipulate images on the canvas.
1) Check if the userInteractionEnabled property of the canvas is set to YES.
2) You can try adding the gestures to the ImageView's rather than the canvas. (I am guessing u want to zoom , rotate n swipe the images).

some guesses:
is this because viewDidLoad method have been called before cavas property been set? In this case, you could try to add recognizers after present popover in another method such as viewDidAppear.
I also agree that the key may be that UIPopoverController allows interaction to other views outside of the popover. So i suggest to move [canvas becomeFirstResponder]; to the end of the viewDidLoad method in PhotoBoothController and try self.view becomeFirstResponder here because you actually add recognizers to self.view.

Related

ScrollsToTop is not working when UIVeiwController is presented from ios8 extension

ScrollsToTop is not working when UIVeiwController is presented from ios8 extension.
But it is working if we presented it from inside the app. Can anyone help? sample code is shared here.
UIScrollView * scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 300) ];
[scrollview setContentSize:CGSizeMake(320, 800)];
scrollview.layer.borderWidth = 1.0;
scrollview.backgroundColor =[UIColor redColor];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"slide1"]];
[scrollview addSubview:imageView];
scrollview.showsVerticalScrollIndicator =YES;
scrollview.scrollsToTop = YES;
scrollview.delegate = self;
UIViewController *a = [[UIViewController alloc] init];
a.view.backgroundColor = [UIColor greenColor];
[a.view addSubview:scrollview];
[self presentViewController:a animated:YES completion:^{
}];
I had same issues & resolved using code bellow.
Some change has done in xcode6. Try this code to make scrollview to top.
[self.ScrollView setContentOffset:CGPointMake(0.0, 0.0) animated:YES];

lag scrolling scrollview with tableview inside it

I have important problem with UIScrollView.
I want to make one app like yahoo weather and using this source code : BTGlassScrollView
in this source code exist one view with name "foregroundView" that is info view. this info view appear when scrolling my ScrollView from bottom to top.
now I make and add my ScrollView by this code:
_viewScroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width + 2*blackSideBarWidth, self.view.frame.size.height)];
[_viewScroller setPagingEnabled:YES];
[_viewScroller setDelegate:self];
[_viewScroller setShowsHorizontalScrollIndicator:NO];
[self.view addSubview:_viewScroller];
_glassScrollView1 = [[BTGlassScrollView alloc] initWithFrame:self.view.frame BackgroundImage:[UIImage imageNamed:#"background3"] blurredImage:nil viewDistanceFromBottom:0 foregroundView:[self customView]];
[_viewScroller addSubview:_glassScrollView1];
in my code I write [self customView] that make me info view and this is customView function:
- (UIView *)customView {
//this method is for make UITableView
[self makeTableBuy:[[self.tableDic objectForKey:#"person"] count]];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _tableBuy.frame.size.width, _tableBuy.frame.size.height)];
view.layer.cornerRadius = 3;
view.backgroundColor = [UIColor colorWithWhite:0 alpha:.3];
[view addSubview:_tableBuy];
return view;
}
- (UITableView*)makeTableBuy:(int)numberOfRow {
_tableBuy = [[UITableView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,numberOfRow*TABLE_HEIGHT) style:UITableViewStyleGrouped];
[_tableBuy setTag:1];
[_tableBuy setBackgroundColor:[UIColor clearColor]];
_tableBuy.showsVerticalScrollIndicator = NO;
_tableBuy.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableBuy.rowHeight = TABLE_HEIGHT;
_tableBuy.scrollEnabled = NO;
_tableBuy.delegate = self;
_tableBuy.dataSource = self;
return _tableBuy;
}
now When I'm scrolling my ScrollView my info view (my tableview) moving to top and appear but my scrolling have so lagging.
please guide me how to fix this lag???

Horizontal UIScrollView in a UITableViewCell

I'm trying to create a simple scrollView inside a tableview cell. Just like on app store, but with simpler scrolling.
The scrollview is showing up but its not scrolling at all. I've tried whole first page on google and many stackoverflow questions, can't seem to find what I'm doing wrong.
if (indexPath.row==0) {
// Clearing out cell background
[cell setBackgroundColor:[UIColor clearColor]];
[cell.contentView setBackgroundColor:[UIColor clearColor]];
// Imageviews for scrollview
UIImageView *imageview1 = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,123)];
UIImageView *imageview2 = [[UIImageView alloc] initWithFrame:CGRectMake(320,0,320,123)];
imageview1.image = [UIImage imageNamed:#"flash2.png"];
imageview2.image = [UIImage imageNamed:#"IMG_2458.JPG"];
// setting up scrollview
self.scrollViewHeader = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,320, 123)];
self.scrollViewHeader.scrollEnabled = YES;
self.scrollViewHeader.delegate = self;
[self.scrollViewHeader setUserInteractionEnabled:YES];
[self.scrollViewHeader setContentSize:CGSizeMake(320, 123)];
[self.scrollViewHeader addSubview:imageview1];
[self.scrollViewHeader addSubview:imageview2];
[cell.contentView addSubview:self.scrollViewHeader];
}
else{
// Normal table cells.
...
}
Thanks in advance for your answers.
In order for a scroll view to scroll, its content size must be greater than its bounds.
You have:
self.scrollViewHeader = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,320, 123)];
and then
[self.scrollViewHeader setContentSize:CGSizeMake(320, 123)];
In this case, they are both the same size, therefore it won't scroll. Do:
self.scrollViewHeader = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,160, 123)];
[self.scrollViewHeader setContentSize:CGSizeMake(320, 123)];

Add UITapRecognizerController to UIImageView

I have an imageview which I had added a tapRecognizer to like this:
recognizer1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap1)];
UIImageView *crossImage = [[UIImageView alloc] initWithFrame:CGRectMake((jrect.origin.x+jrect.size.width), (jrect.origin.y-20), 30, 30)];
crossImage.image = [UIImage imageNamed:#"cross.png"];
[crossImage addGestureRecognizer:recognizer1];
[self addSubview:crossImage];
handleTap method:
- (void)handlePan1:(UITapGestureRecognizer *)recognizer
{
NSLog(#"FV");
}
When I click the image nothing happens. What's wrong?
crossImage.userInteractionEnabled = YES;
You need enable user iteraction. By default is NO for UIImageView.

how to make a imageview do a segue

I have a bunch of imageview generated in a gridview. But now I want that each imageview can do a segue to another screen. Does anybody knows how I can do that? Here is the code of how I generated my imageview and put it into my grid.
UIImageView * myView = [[UIImageView alloc] initWithImage:myImage];
CGRect rect = myView.frame;
rect.origin.x = xCurrent;
rect.origin.y = yCurrent;
myView.frame = rect;
myView.tag = cellCounter;
[gridContainerView addSubview:myView];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap:)];
myView.userInteractionEnabled = YES;
[myView addGestureRecognizer:tap];
Please help
Kind regards
You are looking for a tapGestureRecognizer. Add one of those to your image views and make the action call your segue method.
UIImageView *img = [[UIImageView alloc] init];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(mySequeMethod:)];
img.userInteractionEnabled = YES;
[img addGestureRecognizer:tap];
A:
use a custom button instead of UIImageView, and set the image... and then segue with that button, (it looks the same)
B:
use a gesture recognizer to the view, and use a tap with one finger.