touchesMoved QuartzDemo application - iphone

I am modifying the QuartzDemo application to include swipe detection while UIView is active (a PDF page being displayed in it via Quartz).
This will not work, the event never gets to the QuartzView.m because it sits under scrollview?
touchesBegan: works fine and I can use single tap.
How can I go about with catching touchesMoved while PDF page is being displayed?
I need a simple example with code that does nothing on touchesMoved:, I'll build up on that later.
Please keep in mind that I still want to use the UIScrollview as it is and show PDF content based on selection in that scrollview.

I solved this by implementing touchesBegan, touchesMoved and touchesEnded in QuartzView.m.
I also added this in QuartzViewController.m:
scrollView.maximumZoomScale = 1.0;
scrollView.minimumZoomScale = 1.0;
scrollView.scrollEnabled = NO;
scrollView.pagingEnabled = NO;
Works like I wanted it to :)

Related

Creating Photo library like iPhone, but UIImage tap event handler not working

Hi i am new to iOS programming.
I need to create an photo library like iPhone native photo app. I have found a library MWPhotoBrowser
that provides nearly same UI for photo browsing and its perfect for my requirement. But now i have 2 problems
First is that i need to create a grid layout with thumbnails. Clicking on an thumbnail should display image in full screen with browsing functionality. I tried to dynamically adding UIImageViews in UIScrollView, but UIScrollView is not scrolling and images are going out of screen.
Second is i could not get any tap handler on UIImageView so that i can open an image in full screen.
Looking for some tips here, i am really stuck here.
You can give a shot to this library, it has both features which you are looking for.
https://github.com/gdavis/FGallery-iPhone
Hope it helps :)
For ScrollView scrolling issue you have to increase scrlViewMain.contentSize dynamically. Create a for loop and put bellow code at the end of loop.
scrlViewMain.contentSize = CGSizeMake(0, incermentAsPerYourNeed);
For the tapping issue you have to add TapGesture. Put bellow code when your ImageView creates.
imgView.tag = giveAsPerYourRecordsID;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleImageTap:)];
tap.cancelsTouchesInView = YES;
tap.numberOfTapsRequired = 1;
tap.delegate = self;
[imgView addGestureRecognizer:tap];
[tap release];
And bellow your catch method for tapping.
- (void) handleImageTap:(UIGestureRecognizer *)gestureRecognizer {
UIImageView *tmpImgView = (UIImageView *)gestureRecognizer.view;
}
I have also developed similar functionality a few days ago for my project.
For tap issue you should use UIButton instead of UIImageView, it gives you tap action event. For Scrollview not scrolling, just make sure you update contentSize property of UIScrollView, otherwise it would not scroll according to your subviews.

UIScrollView scrollRectToVisible isn't doing anything

I'm not really sure why this isn't working, hopefully you can help me find the missing piece. I have a UIScrollView with paging enabled. I'm using it for side-scrolling through a tutorial. I have a button that when tapped should scroll the user back to the beginning of the tutorial. I originally tried using the scroll view's frame as the rect to scroll to because that CGRect should represent the first page. I've tried a couple of different CGRects to no avail though.
- (IBAction) touchedButtonReturnToBeginning:(id)sender {
// I've tried several CGRect's, none of which cause the UIScrollView to move.
// CGRect beginning = self.containerScrollView.frame
// CGRect beginning = self.containerScrollView.bounds;
CGRect beginning = CGRectMake(0, 44, 1, 1);
[self.containerScrollView scrollRectToVisible:beginning animated:YES];
}
I have verified that self.containerScrollView is hooked up in my xib as well as the touchedButtonReturnToBeginning action is connected to my button. I've used my debugger to step through this method, so I have verified that it is getting called. All of the variables are appropriately set, but when I call scrollRectToVisible the scroll view just doesn't do anything.
Any ideas?
I don't know why that wouldn't work, but have you tried [self.containerScrollView setContentOffset:CGPointZero animated:YES]?
To make scrollRectToVisible works check your self.containerScrollView.contentSize. It should be big enough :)

OpenFlow AFItem UIImageView touchesBegan

I'm trying to use the OpenFlow project inside of my application.
My target is; when the user tab to any flow item which currently UIImageView according to OpenFlow's AFItemView, it will be zoom-in in the screen (with/without animation) and then user will be able to close and get back to cower flow view in the app.
I didn't get the tocuhesBegan event when I used the default OpenFlow library, then I saw this line
self.multipleTouchEnabled = NO;
self.userInteractionEnabled = NO;
self.autoresizesSubviews = YES;
in the AFOpenFlowView.m, when I change self.userInteractionEnabled = NO; to self.userInteractionEnabled = YES; I'm getting the touchesBegan event in the AFItemView.m that it already implement UIView, but flow doesn't work when I apply to this change.
I'm wondering where is the my mistake ?
Any help and example code would be appreciated.
Edit :
Let me explain my goal;
The target is user will open OpenFlow the scroll images with touch then when the touched any image that inside of the OpenFlow view, selected image will be come with zoom-in or flip or sth. animation. When the user touch to close icon which will be right side of the opened image, screen will be get back to the OpenFlow main screen, I did not find any solution to it on OpenFlow project. It's really urgent.
Regards
I've written this answer before: How to flick through a deck of cards?
The summary:
Once hitTest:withEvent: returns a non-nil value, it's over (by default); that view "owns" the touch (see UITouch.view). Only that view gets touchesBegan/Moved/Ended/Cancelled:withEvent: callbacks.
The touches are being grabbed by AFItemView, so AFOpenFlowView never gets touch events. It may be easier to add the necessary touch-handling to AFOpenFlowView instead.
Alternatively, you can implement touch-forwarding in AFOpenFlowView. It's a bit tricky to get right.

How do I make a side-scrolling iPhone app?

I am working on a side-scrolling iPhone app, and I have every resource, except the actual side scrolling part! How do I make an app so that it side-scrolls? To be more specific, I want the view of the app to scroll when a UIImageview(player) hits the right/left border of the screen.
<:EDIT:>
I am extremely sorry for all of this confusion! All I am making is a SAMPLE iPhone app only to be used in the simulator. In the app, I have a UIImaageview that moves when you touch arrow UIImageviews. PLEASE NOTE THAT ALL INFORMATION SAID BEFORE THIS SENTENCE WORKS PERFECTLY! Now, my problem is that I want the UIView to scroll only ONE picture(this means it doesn't go forever ;)). I have tried using a UIScrollView, but that didn't work. Finally, I am not planning to use Cocos2D or any other game engine besides a basic UIview. This is only a test app, not a coding extravaganza...
If you're writing a game, you may benefit from a lot of the features given to you by engines such as Cocos2D.
Start with a view-based application template so you can get the gist of how this works. Later you can integrate with your existing code.
Create a seamless background image 320 x 960 pixels, named "seamless.png"
Add this ivar to your view controller .h file
UIImageView *bg;
#property (nonatomic, retain) UIImageView *bg;
In your .m file add these #defines before the #implementation line, the #synthesize after.
#define kUpdateRate (1.0 / 60.0)
#define kMoveY (3.0)
#define kTopY (0.0)
#define kBottomY (480.0)
#synthesize bg;
Add this method.
-(void)scrollView; {
float oldY = self.bg.center.y + kMoveY;
float newY = oldY;
if (oldY > kBottomY) {
newY = kTopY;
}
self.bg.center = CGPointMake(self.bg.center.x, newY);
}
Add this to your viewDidLoad method.
self.bg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"endless.png"]];
[self.view addSubview:self.bg];
self.bg.center = CGPointMake(self.bg.center.x, kTopY);
[NSTimer scheduledTimerWithTimeInterval:kUpdateRate target:self selector:#selector(scrollView) userInfo:nil repeats:YES];
When you run the app, you should have a nice scrolling background.
To sum up what happens: A timer is set up to repeatedly call scrollView:
There, the image is moved downwards until it reaches a predefined point (kBottomY), at which time its position is jumped back up to the top (kTopY) and it starts over again.
You can customize it to only scroll when you want it to or scroll the other way on your own, right?
If the image being side-scrolled is large, I'd suggest scrolled view while taking advantage of CATiledLayer. See the WWDC10 Session 104 video and the "Tiling" sample code.
BTW, there is nothing in the Apple docs that seem to prejudge the use of scroll views for utility or menus.
Are you trying to use a UIScrollView? If so, just set your scrollView's content size to something wider than the screen. For example:
self.scrollView.contentSize = CGSizeMake(640, 480);
You should use a UIScollView (http://www.iphonedevsdk.com/forum/iphone-sdk-tutorials/3393-uiscrollview-tutorial.html). Or am I missing the point?
Just make the main view wider than the screen and change the bounds accordingly to show a different portion of the main view. This assumes your main view does have some kind of a limited width. It's slightly trickier if that view just goes forever. In that case you change the bounds and draw the newly revealed content.
If this doesn't make sense then I think you need to reword your question or do some experimentation to narrow down what you're asking.
Take a look at Cocos2D for the iPhone which also includes a choice of 2 collision engines, chipmunk and box2d
I can also recommend the oreilly book iPhone game development, which if you are new to game development will teach you how to roll a basic game framework

iPhone OS: Tap status bar to scroll to top doesn't work after remove/add back

Using this method to hide the status bar:
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
When setting "hidden" back to NO, the tap-to-scroll-to-top (in UIWebView, UITableView, whatever) doesn't work any more, and requires a restart of the app to get the functionality back.
Is this a bug (I filed a rdar anyhow) or have I missed a step? Should I perhaps expect this behavior since the statusBar "loses touch" somehow with the respective view?
You could try setting the ScrollsToTop property to true again after re-showing it:
[currentView setScrollsToTop:YES];
If that's not working, are you definitely only showing one view? If there is more than one scrolling view a scrollViewDidScrollToTop message is ignored...
In iOS 5.0 you can access the scrollview property of the UIWebView
webView.scrollView.scrollsToTop = YES;
The following fix by Alex worked for me. Thanks!
((UIScrollView *)[[webView subviews] objectAtIndex:0]).scrollsToTop = NO;
Being in a hurry this fix worked great, however given more time I might've subclassed the UIWebView and accessed the protected UIScrollView member directly.
The worry I have with Alex' method is that it assumes that UIScrollView is at index zero of the subviews (encapsulation allows private members to change). Which suggests another solution still:
for (UIView* v in [webView subviews])
{
if ([v isKindOfClass:[UIScrollView class]])
{
(UIScrollView *)v.scrollsToTop = NO;
}
}
I was having a similar problem where the scroll-to-top functionality was lost. Turns out this will only work when you have only one active view at a time (within the same scroll view). In my case I had a table view and another view which would fade in/out. Adding a removeFromSuperview at the end of the animation did the trick.
The answer was in the UIScrollView.h file comments:
/*
this is for the scroll to top gesture. by default, a single scroll visible scroll view with this flag set will get the call. if there is more than one visible with this
flag set or the delegeat method returns NO, the view isn't scrolled
*/
#property(nonatomic) BOOL scrollsToTop; // default is YES. if set, special gesture will scroll to top of view after consulting delegate
You can use the following code to have the UIWebView ignore scrollToTop without the extra UIScrollView:
((UIScrollView *)[[webView valueForKey:#"_internal"] valueForKey:#"scroller"]).scrollsToTop = NO;
I had a similar problem after playing a Youtube video within my app. scrollsToTop was still set to YES but tapping the status bar had no effect.
I finally realised that my app window was no longer the key window. After adding the following line to a UIWindow subclass (which I already had for other reasons) everything worked as it should again:
if (![self isKeyWindow]) [self makeKeyWindow];
I just ran across a similar behavior in the app I'm currently working on. In its case, if you load a YouTube video from within a UIWebView, scroll to top stops working for the rest of the application's life cycle. I kind of assume this might happen after loading the movie player as well, but haven't confirmed. That functionality has been around a lot longer and probably has fewer bugs.
When there are multiple scrollview, you can also set scrollUpToTop to NO for the others scrollview. cf:
setScrollsToTop with multiple UIScrollView classes and/or subclasses(UITableView)
I want to add my case, I add an UIWebView on an UIScrollView, as h4xxr had answered on the top:
If there is more than one scrolling view a scrollViewDidScrollToTop message is ignored
So, I get a simply way to make it work on webView: just set the scrollView·s scrollsToTop property false.
And when tap the status bar, it won`t got intercepted by the scrollView, and the webView scrolls to the top!
UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.frame = self.view.bounds;
scrollView.scrollsToTop = false; //igore scrollView`s scrollsToTop
[self.view addSubview:scrollView];
UIWebView *webView = [[UIWebView alloc] init];
webView.frame = scrollView.bounds;
[scrollView addSubview:webView];