the problem is I make a new UIScrollView at Xib and then link the delegate to owner..
some how the delegate doesnt called.. any clue? or simple example for UIScrollView
sorry I am a new ios developer and thank in advance..
the code :
at header
#interface stageViewController : UIViewController<UIScrollViewDelegate>
at .m
#pragma mark drag delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
NSLog(#"scrollViewDidScroll");
} // any offset changes
- (void)scrollViewDidZoom:(UIScrollView *)scrollView{
NSLog(#"scrollViewDidZoom");
}
// called on start of dragging (may require some time and or distance to move)
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
NSLog(#"scrollViewWillBeginDragging");
}
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
NSLog(#"scrollViewWillEndDragging");
}
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
NSLog(#"scrollViewWillBeginDecelerating");
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
NSLog(#"scrollViewDidEndDecelerating");
}
Write scrollView.delegate = self; If you have made it pragmatically.
And if you have your ScrollView in XIB then ctrl+drag from your scrollView to your File's Owner and then set its delegate.
Related
iOS documention says, that the UIWebView class conforms to UIScrollViewDelegate. But an UIWebView instance does not call the scrollViewDidScroll method of its controller. The delegate is set just right by
[webView setDelegate:self];
and webViewDidFinishLoad is called successfully. The controller implements both delegates, UIWebViewDelegate and UIScrollViewDelegate, like this:
#interface WebviewController : UIViewController<UIWebViewDelegate, UIScrollViewDelegate>{
UIWebView *webView;
}
Browsing SO leads to that category solution:
#implementation UIWebView(CustomScroll)
- (void) scrollViewDidScroll:(UIScrollView *)scrollView{
[self.delegate scrollViewDidScroll: scrollView];
}
#end
That category approach does basically the same: Calling the delegate's scrollViewDidScroll method. So why does the the first approach not work?
My guess is you set up delegate only for UIWebView.
Try setting delegate of scrollView.
webView.scrollView.delegate = self
it should be ok.
This is not correct. If you will use:
#implementation UIWebView(CustomScroll)
- (void) scrollViewDidScroll:(UIScrollView *)scrollView{
[self.delegate scrollViewDidScroll: scrollView];
}
#end
You will lose focus when try to enter data on page on iOS7 and more
You need to implement custom class for UIWevView and overwrite scrollViewDidScroll:
- (void) scrollViewDidScroll:(UIScrollView *)scrollView{
[super scrollViewDidScroll:scrollView];
[((id<UIScrollViewDelegate>)self.delegate) scrollViewDidScroll:scrollView];}
From the list of available UIScrollview delegate list . I want to restrict a selective uiscrollview delegate function namely:
(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;
I want to restrict it from calling by the compiler . can i accomplish this . Any suggestions & help are appreciated!!
As mentioned previously you can assign a tag to each of your UIScrollViews (or just the one you need), and then check for that specific tag, or you can compare the UIScrollView in your delegate methods to the one you are interested in.
With tags.
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
if(scrollView.tag == 100){
//do something here
return imgView;
}
return nil;
}
Comparing scrollViews.
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
if([myScrollView isEqual:scrollView]){
//do something here
return imgView;
}
return nil;
}
I want to detect if mytable view has been scrolled, I tried all touch events like this one:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
//my code
}
but it seems that all touch events don't response to scroll but they response only when cells are touched, moved,...etc
Is there a way to detect scroll event of UITableView ?
If you implement the UITableViewDelegate protocol, you can also implement one of the UIScrollViewDelegate methods:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
or
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
For example, if you have a property called tableView:
// ... setting up the table view here ...
self.tableView.delegate = self;
// ...
// Somewhere in your implementation file:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
NSLog(#"Will begin dragging");
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(#"Did Scroll");
}
This is because UITableViewDelegate conforms to UIScrollViewDelegate, as can be seen in the documentation or in the header file.
If you have more than one table views as asked by Solidus, you can cast the scrollview from the callback to tableview as UITableView is derived from UIScrollView and then compare with the tableviews to find the source tableview.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
UITableView* fromTableView = (UITableView*) scrollView;
UITableView* targetTableView = nil;
if (fromTableView == self.leftTable) {
targetTableView = self.leftTable;
} else {
targetTableView = self.rightTable;
}
...
}
These are the methods from UITableViewDelegate using Swift to detect when an UITableView will scroll or did scroll:
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
}
I have 4 UIScrollViews that overlay each other, and they all scroll when you drag a finger across. I however want to make one of them scroll at a different speed than the others.
I have tried using
- (void)scrollViewDidEndDecelerating: (UIScrollView *)scrollView
- (void)scrollViewWillBeginDecelerating: (UIScrollView *)scrollView
- (void)scrollViewDidScroll: (UIScrollView *)scrollView
- (void)scrollViewDidEndDragging: (UIScrollView *)scrollView
- (void)scrollViewDidEndScrollingAnimation: (UIScrollView *)scrollView
to capture when a scroll occurs but none of them are called during or after the scroll.
I have also tried setting the decelerationRate to be different for one of the views but they still all scroll at the same time?
Any ideas?
I guess,you're not implementing UIScrollViewDelegate method.
See the delegate property of UIScrollView.
#property(nonatomic, assign) id<UIScrollViewDelegate> delegate
and set it with the object of the class where you have implemented
UIScrollViewDelegate
methods,
myfirstScrollView.delegate = self;
mysecondScrollView.delegate = self;
.......
....
I want to preface this question with the fact I am new to the iphone application development and many times believe I may be over my head. I am trying to find an action that will allow me to double tap anywhere within my full screen UIScrollView to return to my main menu (MainMenuViewController).
I currently have the following code running for my ScrollViewController...
ScrollViewController.h
#import <UIKit/UIKit.h>
#interface ScrollViewController : UIViewController <UIScrollViewDelegate>
{
}
#end
ScrollViewController.m
#import "ScrollViewController.h"
UIScrollView *myScrollView;
UIPageControl *myPageControl;
#implementation ScrollViewController
- (void)loadScrollViewWithPage:(UIView *)page
{
int pageCount = [[myScrollView subviews] count];
CGRect bounds = myScrollView.bounds;
bounds.origin.x = bounds.size.width * pageCount;
bounds.origin.y = 0;
page.frame = bounds;
[myScrollView addSubview:page];
}
...etc
Any advice or sample code to implement a double tap within the ScrollView Controller to allow me to return to my MainMenuViewController would be greatly appreciated. Also please include any Interface Builder changes to the view (if necessary). I have been pouring over the forums for days and have not been able to successfully implement this action. Thanks...R.J.
First of all, create a subclass of a UIScrollView:
#import <UIKit/UIKit.h>
#interface MyScrollView : UIScrollView {
}
#end
Implement it:
#import "MyScrollView.h"
#implementation MyScrollView
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event {
if (!self.dragging) {
[self.nextResponder touchesEnded: touches withEvent:event];
}
[super touchesEnded: touches withEvent: event];
}
- (void)dealloc {
[super dealloc];
}
#end
Then, use this subclass instead of a normal UIScrollView in your main View Controller. This will call the touchesEnded:withEvent: method (alternatively, you can call any method you want). Then, track for double taps (if you need info on how to do that, let me know).