Q:UITableView scrollViewDidScroll function to change the custom navigationBar's alpha - ios

In my view controller, I have a tableView, and I also add a custom navigationBar on my view controller's view, I want to fade the alpha of my custom navigationBar, but its appears no use, and I printed the alpha of my custom navigationBar, it shows alright, but my custom navigationBar look like no change on its alpha, this is my code:
#pragma mark -- scorllView delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if(scrollView == _tableview){
CGFloat currentOffsetY = scrollView.contentOffset.y;
// 0 ~ 358 -20 ~ 338
float alpha_of_scroll = (currentOffsetY + 20) / 358.0;
NSLog(#"%f", alpha_of_scroll);
_narBarView.alpha = 1 - alpha_of_scroll;
NSLog(#"%f", _narBarView.alpha);
}
}
By the way, I have tested use reactive cocoa, it shows alike to the scrollViewDidScroll function.

Try this:
- (void)viewDidLoad {
[super viewDidLoad];
UIView *overlay = [[UIView alloc] initWithFrame:CGRectMake(0, -20, CGRectGetWidth(self.navigationController.navigationBar.bounds), CGRectGetHeight(self.navigationController.navigationBar.bounds) + 20)];
overlay.userInteractionEnabled = NO;
overlay.backgroundColor = [UIColor orangeColor];
[self.navigationController.navigationBar insertSubview:overlay atIndex:0];
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
}
#pragma mark -- scorllView delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if(scrollView == self.myTableView){
CGFloat offsetY = scrollView.contentOffset.y;
NSLog(#"%f", offsetY);
if (offsetY > -64) {
if (offsetY >= 0) {
[self setNavigationBarAlpha:0];
} else {
[self setNavigationBarAlpha:(-offsetY / 64)];
}
} else {
[self setNavigationBarAlpha:1];
}
}
}
- (void)setNavigationBarAlpha:(CGFloat)alpha {
[[self.navigationController.navigationBar subviews] enumerateObjectsUsingBlock:^(UIView *obj, NSUInteger idx, BOOL *stop) {
obj.alpha = alpha;
}];
}

Related

how to add/show toolbar below status bar in iOS?

in my iOS application, I am adding functionality for collapsing toolbar when table view scrolls. But when toolbar moves above along y axis, I got following result (toolbar contents mixing with status bar contents).
#interface ListViewController () <UITableViewDataSource, UITableViewDelegate>
#property (weak, nonatomic) IBOutlet UILabel *labelPageTitle;
#property (weak, nonatomic) IBOutlet UITableView *listTableView;
#property (nonatomic) CGFloat previousScrollViewYOffset;
#property (weak, nonatomic) IBOutlet NSLayoutConstraint *toolbarTop;
#end
#implementation ListViewController
//- (void)scrollViewDidScroll:(UIScrollView *)scrollView
//{
// CGRect frame = self.toolbars.frame;
// CGFloat size = frame.size.height - 21;
// CGFloat framePercentageHidden = ((20 - frame.origin.y) / (frame.size.height - 1));
// CGFloat scrollOffset = scrollView.contentOffset.y;
// CGFloat scrollDiff = scrollOffset - self.previousScrollViewYOffset;
// CGFloat scrollHeight = scrollView.frame.size.height;
//
// NSLog(#"scrollView.frame - %#", NSStringFromCGRect(scrollView.frame));
// NSLog(#"scrollView.contentInset - %#", NSStringFromUIEdgeInsets(scrollView.contentInset));
//
// CGFloat scrollContentSizeHeight = scrollView.contentSize.height + scrollView.contentInset.bottom;
//
// if (scrollOffset <= -scrollView.contentInset.top) {
// frame.origin.y = 20;
// } else if ((scrollOffset + scrollHeight) >= scrollContentSizeHeight) {
// frame.origin.y = -size;
// } else {
// frame.origin.y = MIN(20, MAX(-size, frame.origin.y - scrollDiff));
// }
//
// [self.toolbars setFrame:frame];
// [self updateBarButtonItems:(1 - framePercentageHidden)];
// self.previousScrollViewYOffset = scrollOffset;
//}
//
//- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
//{
// [self stoppedScrolling];
//}
//
//- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView
// willDecelerate:(BOOL)decelerate
//{
// if (!decelerate) {
// [self stoppedScrolling];
// }
//}
//
//- (void)stoppedScrolling
//{
// CGRect frame = self.navigationController.navigationBar.frame;
// if (frame.origin.y < 20) {
// [self animateNavBarTo:-(frame.size.height - 21)];
// }
//}
//
//- (void)updateBarButtonItems:(CGFloat)alpha
//{
// self.buttonDismiss.customView.alpha = alpha;
// self.labelPageTitle.alpha = alpha;
// self.toolbars.tintColor = [self.toolbars.tintColor colorWithAlphaComponent:alpha];
//}
//
//- (void)animateNavBarTo:(CGFloat)y
//{
// [UIView animateWithDuration:0.2 animations:^{
// CGRect frame = self.toolbars.frame;
// CGFloat alpha = (frame.origin.y >= y ? 0 : 1);
// frame.origin.y = y;
// [self.toolbars setFrame:frame];
// [self updateBarButtonItems:alpha];
// }];
//}
#pragma mark - view controllers life cycle methods
- (void)viewDidLoad {
[super viewDidLoad];
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars=NO;
self.automaticallyAdjustsScrollViewInsets=NO;
[self.view layoutIfNeeded];
_toolbarTop.constant = -34;
[self.listTableView setDataSource:self];
[self.listTableView setDelegate:self];
[Utils updateLabelFontSize:self.labelPageTitle ForInitialHeight:22 andInitialSize:21];
[self.labelPageTitle setText:#"My Category"/*self.productCategory*/];
}
Finally after playing for 4-5 hours, I come across the solution. First of all thanks to #Lion & #Desdenova for help.
Here is the link where I found some hint.
iOS8: How do I make statusBar opaque after navigationBar is hidden using hidesBarsOnSwipe?
as per suggestions in the post I just assigned one UIView at status bar frame with same color of toolbar tint.
Here is my updated code in view did load. Remaining is the same
- (void)viewDidLoad {
[super viewDidLoad];
// if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
// self.edgesForExtendedLayout = UIRectEdgeNone;
//
// self.extendedLayoutIncludesOpaqueBars=NO;
// self.automaticallyAdjustsScrollViewInsets=NO;
[self.view layoutIfNeeded];
_toolbarTop.constant = -34;
[self.listTableView setDataSource:self];
[self.listTableView setDelegate:self];
//let topBar = UIView(frame: UIApplication.sharedApplication().statusBarFrame)
UIView *statusBarView = [[UIView alloc] initWithFrame:[[UIApplication sharedApplication] statusBarFrame]];
statusBarView.backgroundColor = self.view.backgroundColor;
[self.view addSubview:statusBarView];
[Utils updateLabelFontSize:self.labelPageTitle ForInitialHeight:22 andInitialSize:21];
[self.labelPageTitle setText:#"My Category"/*self.productCategory*/];
}
Final Result
Do not pin constraint from TopLayoutGuide.Bottom, instead pin it with superview's top. You your toolbar's top should be pinned with superview's top. Check the below screenshot,

Image not Zoom On double tap in iOS

In my application having gallery functionality.For Scrolling image i used REPagedScrollView and i want to image zoom on pinch using 2 finger and also want zoom on double tap but i unable to to zoom image on double tap
please resolved my problem.
I tried by below code :
.h file
#interface ViewPhotoVC : UIViewController<UIScrollViewDelegate,UIGestureRecognizerDelegate>
{
REPagedScrollView *scrollView;
UIScrollView *image_scroll;
int current_page;
BOOL is_FullScreen;
}
#property (strong,nonatomic) IBOutlet UIView *slider_view;
.m file
-(void)video_image_Gallery
{
scrollView = [[REPagedScrollView alloc] initWithFrame:self.slider_view.bounds];
scrollView.delegate=self;
// scrollView.pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
// scrollView.pageControl.currentPageIndicatorTintColor = [UIColor grayColor];
current_page=0;
for(int i=0;i<[self.PhotoImgArr count];i++){
self.image_view = [[AsyncImageView alloc] initWithFrame:CGRectMake(0,0, self.slider_view.frame.size.width, self.slider_view.frame.size.height)];
// scrollView.frame=CGRectMake(0, 0, screenwidth, screenheight);
image_scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,screenwidth,screenheight)];
self.image_view.backgroundColor=[UIColor clearColor];
self.image_view.contentMode = UIViewContentModeScaleAspectFit;
self.image_view.clipsToBounds = true;
self.image_view.userInteractionEnabled = YES;
self.image_view.autoresizingMask = ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin);
self.image_view.image = [UIImage imageNamed:#"no_image1.png"];
self.image_view.imageURL =[NSURL URLWithString:[self.PhotoImgArr objectAtIndex:i]];
self.image_view.backgroundColor = [UIColor colorWithRed:247.0/255.0 green:246.0/255.0 blue:241.0/255.0 alpha:1];
[image_scroll setDelegate:self];
[image_scroll setShowsHorizontalScrollIndicator:NO];
[image_scroll setShowsVerticalScrollIndicator:NO];
[image_scroll setMaximumZoomScale:8.0];
image_scroll.tag=i+1;
self.PlayVideoBtn.tag=i+1;
self.image_view.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
image_scroll.contentSize = CGSizeMake(self.image_view.bounds.size.width-500, self.image_view.bounds.size.height-300);
image_scroll.decelerationRate = UIScrollViewDecelerationRateFast;
// [image_scroll setMinimumZoomScale:[image_scroll frame].size.width / [self.image_view frame].size.width];
[image_scroll setZoomScale:[image_scroll minimumZoomScale]];
[image_scroll addSubview:self.image_view];
[image_scroll addSubview:self.PlayVideoBtn];
[image_scroll addSubview:self.videoImg];
scrollView.tag=0;
// self.PlayVideoBtn.tag=0;
[scrollView addPage:image_scroll];
}
[self.slider_view addSubview:scrollView];
self.index_lbl.text = [NSString stringWithFormat:#"%d of %lu",(int)self.selected_index+1,(unsigned long)[self.PhotoImgArr count]];
[scrollView scrollToPageWithIndex:self.selected_index animated:YES];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView1
{
if(scrollView1.tag ==0){
CGFloat pageWidth = scrollView1.frame.size.width;
current_page = floor((scrollView1.contentOffset.x - pageWidth / 2.0) / pageWidth) + 1;
self.index_lbl.text = [NSString stringWithFormat:#"%d of %lu",current_page+1,(unsigned long)[self.PhotoImgArr count]];
if(current_page+1==self.PhotoImgArr.count)
{
self.nextBtn.userInteractionEnabled=NO;
self.nextImg.image=[UIImage imageNamed:#"disable_next.png"];
}
else if(current_page==0)
{
self.prevBtn.userInteractionEnabled=NO;
self.prevImg.image=[UIImage imageNamed:#"disable_prev.png"];
}
else
{
self.nextBtn.userInteractionEnabled=YES;
self.prevBtn.userInteractionEnabled=YES;
self.nextImg.image=[UIImage imageNamed:#"next.png"];
self.prevImg.image=[UIImage imageNamed:#"prev.png"];
}
}
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView1 {
if([self.PhotoOrVideo isEqualToString:#"Photo"])
{
if([[scrollView1 viewWithTag:scrollView1.tag].subviews count]>0){
return [[scrollView1 viewWithTag:scrollView1.tag].subviews objectAtIndex:0];
}
}
return nil;
}
Please try the below code:
-(void)setScrollView:(UIScrollView *)scrollView
{
_scrollView=scrollView;
_scrollView.minimumZoomScale=0.2;
_scrollView.maximumZoomScale=3.0;
_scrollView.delegate=self;
}
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.imageView;
}
-(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
{
[self.scrollView flashScrollIndicators];
}

image view not scrollable in scrollview and not fit properly using pure layout

I'm simply trying to place an image into scroll view which is in a main view using purelayout.
And what i'm taking right now is;
Note that view with red background is scroll view. And also the image is not scrollable.
- (void)loadView {
self.view = [[UIView alloc] init];
[self.scrollView addSubview:self.photoView];
[self.view addSubview:self.scrollView];
[self.view setNeedsUpdateConstraints];
}
- (void)updateViewConstraints {
if (!_didSetupConstraints) {
...
...
...
[self.photoView autoPinEdgeToSuperviewEdge:ALEdgeTop];
[self.photoView autoPinEdgeToSuperviewEdge:ALEdgeBottom];
[self.photoView autoPinEdgeToSuperviewEdge:ALEdgeLeft];
[self.photoView autoPinEdgeToSuperviewEdge:ALEdgeRight];
self.didSetupConstraints = YES;
}
[super updateViewConstraints];
}
- (UIImageView *)photoView {
if (!_photoView) {
_photoView = [UIImageView newAutoLayoutView];
_photoView.backgroundColor = [UIColor whiteColor];
}
return _photoView;
}
- (UIScrollView *)scrollView {
if (!_scrollView) {
_scrollView = [UIScrollView newAutoLayoutView];
_scrollView.backgroundColor = [UIColor redColor];
_scrollView.maximumZoomScale = 2.0;
_scrollView.minimumZoomScale = 0.5;
}
return _scrollView;
}
Ok, it seems working well with two changes i did.
Firstly i set self.photoView size manually.
[self.photoView autoSetDimensionsToSize:CGSizeMake([HelperModel screenWidth], [HelperModel screenHeight] -[HelperModel viewHeight:self.navigationController.navigationBar] -20.0)];
HelperModel.m
#implementation HelperModel
+ (CGFloat)screenWidth {
return [[UIScreen mainScreen] bounds].size.width;
}
+ (CGFloat)screenHeight {
return [[UIScreen mainScreen] bounds].size.height;
}
+ (CGFloat)viewHeight:(UIView *)view {
return CGRectGetHeight(view.frame);
}
+ (CGFloat)photoDetailHeight {
return [HelperModel screenHeight] -20;
}
#end
Secondly,
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
for zooming feature and if the zoomed image exceeds the bounds of scroll view, then the image can be scrolled properly.

hide toolbar at bottom of UiWebView when scrolling down

I have the following code that successfully hides the bottom toolbar when NOT at the top of the web view as shown in attached images. (below)
What I am trying to do is hide the toolbar completely and then expand the web view to take up the extra space (similar to how Safari does this). Any help would be great!
- (void)viewDidLoad
{
[super viewDidLoad];
if (self.url != nil)
{
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[StoreWebViewController checkAndPrependProtocolForUrl:self.url]]]];
self.webView.delegate = self;
}
for (id subview in self.webView.subviews)
{
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
{
UIScrollView * s = (UIScrollView*)subview;
originalDelegate = s.delegate;
s.delegate = self;
break;
}
}
}
- (void)scrollViewDidScroll :(UIScrollView *)scrollView
{
if (scrollView.contentOffset.y == 0) //Show toolbar when at top
{
[self.toolbar setHidden:NO];
}
else
{
[self.toolbar setHidden:YES];
}
[originalDelegate scrollViewDidScroll: scrollView];
}
I have made this in an app, using text area, so i think its the same by replacing textView with webView.
Initialize directions & flags
#implementation YourViewController{
BOOL tap;
BOOL hideNav;
BOOL mustShowNav;
}
#synthesize webView;
typedef enum ScrollDirection {
ScrollDirectionNone,
ScrollDirectionRight,
ScrollDirectionLeft,
ScrollDirectionUp,
ScrollDirectionDown,
} ScrollDirection;
viewDidLoad
- (void)viewDidLoad
{
webView.delegate = self;
hideNav = NO;
mustShowNav = NO;
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(webViewTapped:)];
gestureRecognizer.delegate = self;
[self.webView addGestureRecognizer:gestureRecognizer];
}
The scroll
- (void)scrollViewDidScroll:(UIScrollView*)scrollView
{
ScrollDirection scrollDirection;
if (lastContentOffset.y < scrollView.contentOffset.y)
scrollDirection = ScrollDirectionDown;
else
scrollDirection = ScrollDirectionUp;
float endScrolling = scrollView.contentOffset.y + scrollView.frame.size.height;
if (scrollDirection == ScrollDirectionDown && scrollView.contentOffset.y > 50 && !mustShowNav) {
hideNav = YES;
tap = 0;
} else {
hideNav = NO;
}
if (scrollDirection == ScrollDirectionUp && mustShowNav){
hideNav = NO;
mustShowNav = NO;
}
if (scrollDirection == ScrollDirectionDown && endScrolling > scrollView.contentSize.height - 50 && !mustShowNav) {
mustShowNav = YES;
}
[[self navigationController] setToolbarHidden:hideNav animated:YES];
lastContentOffset = scrollView.contentOffset;
[originalDelegate scrollViewDidScroll: scrollView];
}
The tap gesture
- (void)webViewTapped:(id)sender
{
if(!tap){
hideNav = NO;
tap = 1;
} else {
hideNav = YES;
tap = 0;
}
[[self navigationController] setToolbarHidden:hideNav animated:YES];
}
Hope this helps you.
The best solution would be to let your Javascript trigger those events and the hosting view controller should handle them.

Second ScrollView doesn't zoom or scroll

I have two Scroll View's in a xib, and they both contain a very large image that should start with it completely scaled down to fit. The first ScrollView works perfectly, objects are all moving around correctly when you zoom or scroll, but the second ScrollView starts completely zoomed in, unable to zoom out.
The ScrollView is now showing 25% of the image(completely zoomed in at 0,0) and also cannot be dragged to see the rest. If I pinch to zoom, the image moves diagonally up and left without zooming at all, I can now drag the image back to 0,0 and back down the the max point it scrolled diagonally.
.h file
UIScrollView *_scrollView;
UIScrollView *_miamiScrollView;
UIView *_mapImageView;
UIView *_mapMiamiView;
UIView *_mapContentView;
NSArray *_autoLayoutViews;
NSArray *_staticViews;
#property (strong, nonatomic) IBOutlet UIScrollView *scrollView;//(linked to working scrollview)
#property (strong, nonatomic) IBOutlet UIScrollView *miamiScrollView;//(Linked to 'broken' scrollview)
.m file
- (void)viewDidLoad
{
[self _customizeViews];
}
- (void) _customizeViews
{
UIImageView *mapImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"MainGameDisplay.jpg"]];
mapImageView.userInteractionEnabled = YES;
UIImageView *mapMiamiView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"miami.jpg"]];
mapMiamiView.userInteractionEnabled = YES;
_mapContentView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 568, 270)];
_mapContentView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
_mapContentView.clipsToBounds = YES;
_mapContentView.userInteractionEnabled = YES;
[_mapContentView addSubview:_scrollView];
[_mapContentView addSubview:_miamiScrollView];
[self.view addSubview:_mapContentView];
[self.view sendSubviewToBack:_mapContentView];
UIScrollView *scrollView = _scrollView;
CGRect scrollFrame = scrollView.frame;
scrollFrame.origin = CGPointZero;
scrollView.frame = scrollFrame;
scrollView.delegate = self;
scrollView.minimumZoomScale = 1;
scrollView.maximumZoomScale = 1.0;
[scrollView addSubview:mapImageView];
scrollView.contentSize = mapImageView.frame.size;
_scrollView = scrollView;
_mapImageView = mapImageView;
UIScrollView *miamiScrollView = _miamiScrollView;
CGRect miamiScrollFrame = CGRectMake(0 , 270, 568, 270);
scrollFrame.origin = CGPointZero;
miamiScrollView.frame = miamiScrollFrame;
miamiScrollView.delegate = self;
miamiScrollView.minimumZoomScale = 0.125;
miamiScrollView.maximumZoomScale = 1;
[miamiScrollView addSubview:mapMiamiView];
miamiScrollView.contentSize = mapMiamiView.frame.size;
_miamiScrollView = miamiScrollView;
_mapMiamiView = mapMiamiView;
[self _setupAutolayoutViews];
[self _setupStaticViews];
[self _zoomToFit: _scrollView];
[self _zoomToFit: _miamiScrollView];
[self _updatePositionForViews:_autoLayoutViews];
}
- (void) _zoomToFit: (UIScrollView*)view
{
CGFloat contentWidth = view.contentSize.width;
CGFloat contentHeigth = view.contentSize.height;
CGFloat viewWidth = view.frame.size.width;
CGFloat viewHeight = view.frame.size.height;
CGFloat width = viewWidth / contentWidth;
CGFloat heigth = viewHeight / contentHeigth;
CGFloat scale = MAX(width, heigth);
if ( scale < view.minimumZoomScale ) {
view.minimumZoomScale = scale;
} else if ( scale > view.maximumZoomScale ) {
view.maximumZoomScale = scale;
}
view.zoomScale = scale;
}
#pragma mark - Positions
- (void) _updatePositionForViews:(NSArray *)views
{
CGFloat scale = _scrollView.zoomScale;
CGPoint contentOffset = _scrollView.contentOffset;
contentOffset.x -= _scrollView.frame.origin.x;
contentOffset.y -= _scrollView.frame.origin.y;
for ( UIView *view in views ) {
CGPoint basePosition = [self _basePositionForView:view];
[self _updatePositionForView:view scale:scale basePosition:basePosition offset:contentOffset];
}
}
- (CGPoint) _basePositionForView:(UIView *)view
{
NSString *key = [NSString stringWithFormat:#"%d", view.tag];
NSString *stringValue = [_coordinates objectForKey:key];
NSArray *values = [stringValue componentsSeparatedByString:#":"];
if ( [values count] < 2 ) return CGPointZero;
CGPoint result = CGPointMake([[values objectAtIndex:0] floatValue], [[values objectAtIndex:1] floatValue]);
return result;
}
- (void) _updatePositionForView:(UIView *)view scale:(CGFloat)scale basePosition:(CGPoint)basePosition offset:(CGPoint)offset;
{
CGPoint position;
position.x = (basePosition.x * scale) - offset.x;
position.y = (basePosition.y * scale) - offset.y;
CGRect frame = view.frame;
frame.origin = position;
view.frame = frame;
}
//////////////////////////////////////////////////////////////////////////////////////
#pragma mark - UIScrollViewDelegate
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
{
[self _lockInteraction];
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
{
[self _unlockInteraction];
}
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view
{
[self _lockInteraction];
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale;
{
[self _unlockInteraction];
}
- (void) _lockInteraction
{
[self _setControls:_staticViews interacted:NO];
[self _setControls:_autoLayoutViews interacted:NO];
}
- (void) _unlockInteraction
{
[self _setControls:_staticViews interacted:YES];
[self _setControls:_autoLayoutViews interacted:YES];
}
- (void) _setControls:(NSArray *)controls interacted:(BOOL)interacted
{
for ( UIControl *control in controls ) {
if ( [control isKindOfClass:[UIControl class]]) {
control.userInteractionEnabled = interacted;
}
}
}
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
[self _updatePositionForViews:_autoLayoutViews];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[self _updatePositionForViews:_autoLayoutViews];
}
- (UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView;
{
return _mapImageView;
}
//DEFAULT BUTTONS.
- (void) _setupAutolayoutViews
{
UIButton *btn1 = [UIButton buttonWithType: UIButtonTypeDetailDisclosure];
[btn1 addTarget:self action:#selector(quickTest:) forControlEvents:UIControlEventTouchUpInside];
btn1.tag = kAddContactButton;
btn1.center = CGPointZero;
[_mapContentView addSubview:btn1];
_autoLayoutViews = [[NSArray alloc] initWithObjects:btn1, nil];
}
//CUSTOM BUTTONS.
- (void) _setupStaticViews
{
UIButton *openMiamiButton = [UIButton buttonWithType:UIButtonTypeCustom];
[openMiamiButton setBackgroundImage:[UIImage imageNamed:#"logo.png"] forState:UIControlStateNormal];
[openMiamiButton addTarget:self action:#selector(quickTest:) forControlEvents:UIControlEventTouchUpInside];
openMiamiButton.frame = CGRectMake(0.0 ,0.0, 50.0, 50.0);
openMiamiButton.tag = OpenMiamiButton;
openMiamiButton.enabled = YES;
openMiamiButton.alpha = 0.5;
[_mapImageView addSubview:openMiamiButton];
_staticViews = #[openMiamiButton,];
for ( UIView *view in _staticViews ) {
CGPoint point = [self _basePositionForView:view];
CGRect frame = view.frame;
frame.origin = point;
view.frame = frame;
}
}
//And for the transition between views:
-(void) quickTest: (UIButton *)button
{
/*
if (!openMiami)
openMiami = [[MiamiGameDisplay alloc] initWithNibName:nil bundle:nil];
openMiami.mainPage = self;
[self.navigationController pushViewController:openMiami animated:YES];
*/
if (!testBool){
[UIView animateWithDuration:0.5f
animations:^{
_scrollView.frame = CGRectMake(0 , -270, 568, 270);
}
completion:Nil];
[UIView animateWithDuration:0.5f
animations:^{
_miamiScrollView.frame = CGRectMake(0 , 0, 568, 270);
}
completion:Nil];
testBool=YES;
}
else {
[UIView animateWithDuration:0.5f
animations:^{
_miamiScrollView.frame = CGRectMake(0 , 270, 568, 270);
}
completion:Nil];
[UIView animateWithDuration:0.5f
animations:^{
_scrollView.frame = CGRectMake(0 , 0, 568, 270);
}
completion:Nil];
testBool=NO;
}
}
I've run into a similar issue with scrollViews. Basically, as far as I can tell, only the last scrollView added to the window will respond as a scrollView.
You can produce the same effect with any other type of object being added to the window before the scrollView.
Example :
[[self window] addSubview:logo];
[[self window] addSubview:scrollView];
Will work, but:
[[self window] addSubview:scrollView];
[[self window] addSubview:logo];
will not. (Currently running against iOS 6.1.2 and xCode 4.6.1)

Resources