I wanted to know how can we implement the cover flow effect for the list of pdfs and on double tap ,it should open respective pdf. I m really struck between ,please help me out
thanks in advance
In openFlowView.m file search this method
- (void)awakeFromNib {
[self setUpInitialState];
}
Now when you find this replace this method by below or add lines of tapGestureRecognizer.
- (void)awakeFromNib {
[self setUpInitialState];
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(screenTapped:)];
[tapRecognizer setNumberOfTapsRequired:2];
[self addGestureRecognizer:tapRecognizer];
[tapRecognizer release];
}
screenTapped is my method that gets called when I tap twice on cover flow.
- (void)screenTapped:(UITapGestureRecognizer *)tap {
NSLog(#"Screen tapped");
//put your points of your coverflow coordinates
if(coverPointimage.x > 0 && coverPointimage.x <= 265 && coverPointimage.y >0 && coverPointimage.y <= 205){
[self imageClicked];//either write code or made seperate method that should gets called when you do double tap.
}
}
Hope this code will save your couple of hours.Happy Coding.
You should try out the Tapku Library for coverflow effect. Its really easy and customizable. You can find it here.
Related
I use a UIImagePickerController (photoPicker) to take pictures with the camera, and edit those picture (allowEditing = YES). The user can switch between Camera and Library with a button in photoPicker.view, but I want to remove this button when photoPicker is in editing mode.
In photoLibrarySourceType the picker uses a push to show editing mode, so it works with this method:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (navigationController == photoPicker) {
NSLog(#"navigation ");
if ([navigationController.viewControllers indexOfObject:viewController] == 1)
{
// If second UIViewController, set your overlay.
NSLog(#"editing");
}
}
}
But in cameraSourceType, there is no navigation between camera and editing mode.
I came up with a little hack and it works for me. Am still a little new so please optimize at will as i couldn't find another way to do it.
The basic idea is to create an invisible button over the default camera button that performs a method that calls [uiimagepickercontroller takePicture]
here is my sample code
#implementation myViewController
{
UIImagePickerController *myImagePickerController;
UIButton * fakeCameraButton;
}
- (IBAction)showImagePicker:(id)sender{
// accessible camera validations implied
myImagePickerController = [[UIImagePickerController alloc]init];
myImagePickerController.sourceType=UIImagePickerControllerSourceTypeCamera;
myImagePickerController.showsCameraControls = YES;
myImagePickerController.delegate=self;
myImagePickerController.allowsEditing=YES;
CGFloat myViewHeight = 100; // you play around with the positions to get your desired frame size. This worked for me
UIView * myView = [[UIView alloc] initWithFrame:CGRectMake(0, myImagePickerController.view.frame.size.height - myViewheight, picker.view.frame.size.width, myViewheight)];
fakeCameraButton = [[UIButton alloc] initWithFrame:CGRectMake(myView.frame.size.width / 2 - 30, myView.frame.size.height/2-15, 60, 60)];// position it over the default camera button
[fakeCameraButton addTarget:self action:#selector(cameraButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[fakeCameraButton setTitle:#"" forState:UIControlStateNormal];
[myView addSubview:fakeCameraButton];
myImagePickerController.cameraOverlayView = myView;
[self presentViewController:myImagePickerController animated:YES completion:nil];
}
-(void)cameraButtonPressed{
// Make sure you check if camera is ready before this method.
[myImagePickerController takePicture];
// you are in editing/preview mode here if allowsEditing = YES
// you can remove all your custom overlay views by
myImagePickerController.cameraOverlay = nil
}
Like i said before just make sure you check if camera is ready. You can find answers here on stackoverflow on how to do it.
This code may suck so editing or alternative solutions are welcomed.
I need dev buddy to help me learn more about ios dev and ask questions. anyone interested?
I have two labels in two different positions, when both labels are tapped at the same time i want another label to show a success message.
How do I accomplish this? I can recognize a single tap or double tap with one or more finger touches but this is a different scenario. Please help. I tried this, but it does not work.
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap:)];
tapRecognizer.numberOfTapsRequired = 1;
tapRecognizer.numberOfTouchesRequired = 2;
tapRecognizer.delegate = self;
[self.view addGestureRecognizer:tapRecognizer];
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if (touch.view == tap2 && touch.view == tap1)
{
result.text = #"success";
}
return YES;
}
Thanks in advance.
What you're trying to detect isn't really a single gesture.
I'd suggest adding a tap gesture recogniser to each button. The handler would:
Store the time of the tap (at the moment that the handler is called)
Compare this time with the time that the other button was last
tapped. If the times are very similar (perhaps 0.25 secs apart),
consider that they've both been tapped simultaneously and react
accordingly.
Play with the time interval on a real device to find the ideal amount.
UPDATE:
A code snippet that obviously hasn't been tested in any way:
- (void)handleButton1Tap:(UITapGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateEnded)
{
self.button1TapTime = CACurrentMediaTime();
[self testForSimultaneousTap];
}
}
- (void)handleButton2Tap:(UITapGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateEnded)
{
self.button2TapTime = CACurrentMediaTime();
[self testForSimultaneousTap];
}
}
- (void)testForSimultaneousTap
{
if (fabs(self.button1TapTime - self.button2TapTime) <= 0.2)
{
// Do stuff
}
}
where self.button1TapTime and self.button2TapTime are member variables (doubles).
Tim
Formally I had accepted termes's answer first and that worked too, but I have found a more simpler solution to this process. There is no need for two gesture recognizers, it is achievable with a simple tap gesture recognizer with number of touches count to two. Here is the code:
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap:)];
tapRecognizer.numberOfTapsRequired = 1;
tapRecognizer.numberOfTouchesRequired = 2;
tapRecognizer.delegate = self;
[self addGestureRecognizer:tapRecognizer];
Now, in the handle tap method we can easily get the two touch points by "locationOfTouch:inView:", a instance method of UIGestureRecognizer class. So in the handleTap: method we need to check if the two touch points are in the desired location. Here is the code:
-(void)handleTap:(UITapGestureRecognizer*)recognizer
{
if (recognizer.state == UIGestureRecognizerStateEnded)
{
CGPoint point1 = [recognizer locationOfTouch:0 self];
CGPoint point2 = [recognizer locationOfTouch:1 self];
if ([self validateTapIn:point1 and:point2])
{
resultLabel.text = #"success";
}
}
}
-(BOOL)validateTapIn:(CGPoint)point1 and:(CGPoint)point2
{
return
(CGRectContainsPoint(label1.frame, point1) && CGRectContainsPoint(label2.frame,:point2)) ||
(CGRectContainsPoint(label1.frame, point2) && CGRectContainsPoint(label2.frame, point1));
}
I am faceing a small prob. Please help me.
When i press and hold on my view my function called 2-3 times and some times after releasing hold the long press function again called.
In View did load
-(void)viewdidload
{
UILongPressGestureRecognizer *longPressGesture =
[[[UILongPressGestureRecognizer alloc]
initWithTarget:self action:#selector(longPress:)] autorelease];
[self.view addGestureRecognizer:longPressGesture];
[self.view release];
}
-(void)longPress:(UILongPressGestureRecognizer *)sender
{
NSLog(#"******Long Press*******");
}
Long press printed many times.
You probably want to just return from longPress if the gesture has not ended. Put this code right at the top of longPress:
if (sender.state != UIGestureRecognizerStateEnded)
{
return;
}
I was thinking of an application where user could select a location on an iphone app. I have googled it and didn't find anything useful.
My question is, is it possible to let the user select a location from an iphone app using MapKit/CLLocation? If yes, please help me where should i start.
Thanks
You can add a long press gesture recognizer to the map:
UILongPressGestureRecognizer* lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(handleLongPress:)];
lpgr.minimumPressDuration = 1.5;
lpgr.delegate = self;
[self.map addGestureRecognizer:lpgr];
[lpgr release];
In the handle long press method get the CLLocationCordinate2D:
- (void) handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
/*
Only handle state as the touches began
set the location of the annotation
*/
CLLocationCoordinate2D coordinate = [self.map convertPoint:[gestureRecognizer locationInView:self.map] toCoordinateFromView:self.map];
[self.map setCenterCoordinate:coordinate animated:YES];
// Do anything else with the coordinate as you see fit in your application
}
}
Take a look at this SO answer. The answer tells you not only how to get the coordinate, but also how to put a pin (annotation) on the map.
I found an example code for showing PDF file on a UIScrollView with horizontal scrolling. It works fine, but problem is it shows only 2 pages of PDF. I tried in my best to figure out the issue, but I couldn't figure it. Can you please give me help?
I looked at that sample project you pointed to in this question and like you, I can see it only displays two pages of whatever PDF file it's given to display.
The problem with the sample code comes in the PDFViewController.m file. For these lines:
PDFScrollView *page = [self dequeueRecycledPage];
if (page == nil) {
page = [[[PDFScrollView alloc] initWithPage:index + 1 frame:[self frameForPageAtIndex:index]] autorelease];
}
I added
else {
[page setPage: index inFrame:[self frameForPageAtIndex: index]];
}
And also these new lines into PDFScrollView.h
- (void) setPage: (NSInteger) onPage inFrame:(CGRect)frame;
And PDFScrollView.m
- (void) setPage: (NSInteger) onPage inFrame:(CGRect) frame
{
if(pdfView)
{
[pdfView removeFromSuperview];
[pdfView release];
}
self.frame = frame;
self.index = onPage;
pdfView = [[PDFViewTiled alloc] initWithPage:onPage frame:self.frame];
[self addSubview:pdfView];
}
This isn't a perfect fix. You'll see the drawing isn't proper, especially when backing up pages. I'll leave that to you as an exercise to take care of, but hopefully this is a nice start.
And I hope it helps you out.