Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Solved! I incorporated Notifications instead of trying to directly call a method from a subview.</p> <p>Quick overview of my setup. UIViewController FishIDView contains a UIScrollView called scrollView. scrollView has a subview XMLView. XMLView has a button that shows its subview, flipView. I wanted scrolling to be disabled on scrollView when flipView was visible.</p> <p>In XMLView.h (with irrelevant code omitted):</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import &lt;QuartzCore/QuartzCore.h&gt; #define kApplicationDidStopScrollingNotification @"StopScroll" #define kApplicationDidResumeScrollingNotification @"ResumeScroll" #import "FishIDView.h" @interface XMLView : UIView { IBOutlet UIButton *infoButton; IBOutlet UIButton *closeButton; IBOutlet UIView *flipView; } @property (nonatomic, retain) IBOutlet UIButton *infoButton; @property (nonatomic, retain) IBOutlet UIButton *closeButton; - (IBAction)goToInfo; - (IBAction)closeSubView; @end </code></pre> <p>In XMLView.m:</p> <pre><code>#import "XMLView.h" @implementation XMLView @synthesize infoButton, closeButton; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code } return self; } //Allows button to be pressed while contained in subview of scrollview - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { CGPoint hitPoint = [infoButton convertPoint:point fromView:self]; CGPoint closePoint = [closeButton convertPoint:point fromView:flipView]; if ([infoButton pointInside:hitPoint withEvent:event]) return infoButton; if ([closeButton pointInside:closePoint withEvent:event]) return closeButton; return [super hitTest:point withEvent:event]; } -(IBAction)goToInfo { //post notification for FishIDView to listen to to trigger method that disables scrolling [[NSNotificationCenter defaultCenter] postNotificationName:kApplicationDidStopScrollingNotification object:nil]; [self addSubview:flipView]; //custom transition between views. A cross-fade effect flipView.alpha = 0.0f; [UIView beginAnimations:@"fadeInSecondView" context:NULL]; [UIView setAnimationDuration:0.5]; flipView.alpha = 1.0f; [infoButton setEnabled:FALSE]; [UIView commitAnimations]; } - (IBAction)closeSubView { //post notification to resume scrolling [[NSNotificationCenter defaultCenter] postNotificationName:kApplicationDidResumeScrollingNotification object:nil]; flipView.alpha = 1.0f; [UIView beginAnimations:@"fadeInSecondView" context:NULL]; [UIView setAnimationDuration:0.5]; flipView.alpha = 0.0f; [infoButton setEnabled:TRUE]; [UIView commitAnimations]; [flipView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1.2]; } @end </code></pre> <p>Make sure to put #import "XMLView.h" into your FishIDView.h file at the top and create the -(void) methods at the bottom.</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "XMLView.h" @class AppDelegate; @interface FishIDView : UIViewController &lt;UIScrollViewDelegate&gt; { ... } @property ... //These are the 2 methods that turn scrolling on and off -(void) stopScrolling; -(void) resumeScrolling; @end </code></pre> <p>Then in FishIDView.m</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [scrollView setScrollEnabled:YES]; //Listen for the notification to stop scrolling [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopScrolling) name:kApplicationDidStopScrollingNotification object:nil]; //Listen for the notification to resume scrolling [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resumeScrolling) name:kApplicationDidResumeScrollingNotification object:nil]; [self layoutSubview]; } -(void) stopScrolling { [scrollView setScrollEnabled:NO]; NSLog(@"NO more scrolling!!!"); } -(void) resumeScrolling { [scrollView setScrollEnabled:YES]; NSLog(@"begin scrolling again!!"); } </code></pre> <p>If anyone has questions or is having trouble implementing this, I'll be happy to share more of my code. I just omitted most of it because it doesn't really pertain to this subject.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload