UIScrollView starts automatically in double size - ios

I have an image that I want to display fullscreen in my app using UIScrollView and UIImageView, the image size is 640 x 2754 and I want to show it automatically in full screen mode in minimum zoom.
This is the code:
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"EquationPage.png"]]; self.imageView = tempImageView;
[tempImageView release];
scrollView.maximumZoomScale = 3.0;
scrollView.minimumZoomScale = 0.5;
self.scrollView.contentSize=CGSizeMake(640,2754);
scrollView.clipsToBounds = YES;
scrollView.delegate = self;
[scrollView addSubview:imageView];

To do this, you will have to use the setZoomScale:animated: method of UIScrollView. Confusingly, this method will not work unless you have a (non-nil) delegate set for your scroll view, which responds to -viewForZoomingInScrollView. Read the UIScrollView documentation for how to do this. For more info, you can also read this section about handling zooming with a UIScrollView.

Related

Change width and add a circular scroller to a UIScrollView

I am trying to increase the width of the scrollbar and add a circular scroller. Shall I use an image for the circle? I do not see any property or method of UIScrollView to change the width of the scroller
I tried the following:
UIScrollView *myScroll = [[UIScrollView alloc] init];
myScroll.frame = self.view.bounds; //scroll view occupies full parent view!
//specify CGRect bounds in place of self.view.bounds to make it as a portion of parent view!
myScroll.contentSize = CGSizeMake(400, 800); //scroll view size
myScroll.backgroundColor = [UIColor grayColor];
myScroll.showsVerticalScrollIndicator = YES; // to hide scroll indicators!
myScroll.showsHorizontalScrollIndicator = YES; //by default, it shows!
myScroll.scrollEnabled = YES; //say "NO" to disable scroll
[myScroll setBackgroundColor:[UIColor redColor]];
myScroll.indicatorStyle = UIScrollViewIndicatorStyleWhite;
[self.view addSubview:myScroll];
This custom ScrollView Solved all my problems https://github.com/BasheerSience/BRScrollBar

Adding long press gesture to UIImageView inside Scrollview

I've been researching this for a couple of hours now and nothing seems to work. I have a UIScrollView as an IBOutlet and am adding two UIImageViews via code. One is a background image and the 2nd is a photo. Everything works fine here. I am trying to add a long press gesture to the second photo but it doesn't seem to be working. Here is my code. I hope someone can see my problem.
// loop thru images array
UIImage *bgFrame = [UIImage imageNamed:#"photo-frame.png"];
UIImageView *bgImageView = [[UIImageView alloc] initWithImage:bgFrame];
bgImageView.frame = CGRectMake(posX, posY, 100, 100);
[self.scroll addSubview:bgImageView];
NSString *photoName = [self.photoArray objectAtIndex:i];
UIImage *photo = [self.utils getClientPhoto:photoName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:photo];
imageView.userInteractionEnabled = YES;
imageView.frame = CGRectMake(6, 9, 89, 71);
imageView.tag = i;
[bgImageView addSubview:imageView];
// add long press for deletion
UILongPressGestureRecognizer *lPressed = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:#selector(imageLPressed:)];
lPressed.delegate = self;
lPressed.minimumPressDuration = 0.4;
[imageView addGestureRecognizer:lPressed];
imageView.userInteractionEnabled = YES; not needed, it always work fine. Setting delegate to gestureRecognizer is optional too. First of all try to add imageView to self.scroll subviews not to bgImageView. After that check your scrollView content size, if your image is out of dat size it can be visible but not available. Try to replace imageview with uibutton and check for it's uitouchupinside event.
Enable UserInteraction on bgImageView andimageView.

Adding a UIImageView as a subview of UILabel, image not appearing

So, when I do this with a regular old view:
UIView *topBlock = [[UIView alloc] initWithFrame:CGRectMake(0,-frameSize.height, frameSize.width, frameSize.height/2)];
[viewController.view addSubview:topBlock];
topBlock.autoresizesSubviews = NO;
topBlock.clipsToBounds = YES;
UIImage *topImage = [UIImage imageNamed:#"BloktLayout"];
UIImageView *topImageView = [[UIImageView alloc] initWithImage:topImage];
topImageView.frame = viewController.view.frame;
[topBlock addSubview:topImageView];
I get the nice old image where I want it, in the top view. But the middle view is a UILabel, and when I try the same thing:
UILabel *midBar = [[UILabel alloc] initWithFrame:CGRectMake(midBarOrigin.x, midBarOrigin.y, midBarWidth, midBarHeight)];
midBar.text = #"Blokt";
midBar.textColor = [UIColor blackColor];
midBar.textAlignment = NSTextAlignmentRight;
midBar.font = [UIFont fontWithName:#"HelveticaNeue-UltraLight" size:80.0f];
[viewController.view addSubview:midBar];
midBar.autoresizesSubviews = NO;
midBar.clipsToBounds = YES;
UIImage *midImage = [UIImage imageNamed:#"BloktLayout"];
UIImageView *midImageView = [[UIImageView alloc] initWithImage:midImage];
midImageView.frame = viewController.view.frame;
[midBar addSubview:midImageView];
I don't see any image at all in the UILabel. Any help?
Seems like the issue is related to your frames.
Tough to say without additional info. Can you post viewController.view.frame, frameSize, and midBarOrigin / midBarWidth / midBarHeight?
In the second codeblock, midBar.clipsToBounds == YES, but it looks like the midImageView.frame is likely very different / outside of midBar.frame in which case it wouldn't be visible.
Edit Some screenshots would help but aren't necessary
Edit 2 Note that subviews' origin points are always relative to the coordinate system of their superview, never relative to the coordinate system of any other view in the view heierarchy. This is likely the heart of the issue here. If you do want to convert CGPoints or CGRects from one coordinate system to another there are methods on UIView such as convertRect: and convertPoint: etc.
Interface Builder doesn't even let you add a control inside of a UILabel.
Instead, if you wish to group multiple controls, you can add them both as subviews of a UIView.
In other words, your image view and label can share the same superview, but the image view cannot be a subview of the label.
If they share the same superview, you can position the image view behind the label, and it should appear "through" the label as long as the label's background is clear.
Simple Way to do.....
You can add UIImageView, UILabel as subview of cell.textLabel
UIImageView *statusImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 4, 8, 8)];<br/>statusImage.backgroundColor = [UIColor redColor];<br/>
statusImage.layer.cornerRadius = 4;<br/>
statusImage.clipsToBounds = YES;<br/>
[cell.textLabel addSubview:statusImage];<br/>
UILabel *Lbl = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, cell.textLabel.frame.size.width - 15, cell.textLabel.frame.size.height)];<br/>
Lbl.text = #"xyz";<br/>
[cell.textLabel addSubview:Lbl];<br/>
I just had this problem as well.
I found that ImageView was behind the label.
When I replaced label with UIView, it works properly.

UIScrollview overlapping mainview content

Currently, I have this feature in my app where I implemented a UIScrollview that is pretty thin in height but long in width...
As you can see, the UIScrollView is OVERLAPPING the backgroundview... Not that white background is a UIView to which I added the UIScrollView as a SUBVIEW.
Question is, how is the UIScrollView overlapping the black background content when it's just added to the subview?
Here is my init method for the UIScrollView..
self = [super init];
if (self) {
self.frame = CGRectMake(0, 0, 280, 70);
self.contentSize = CGSizeMake(480, 70);
self.showsHorizontalScrollIndicator = NO;
self.bounces = NO;
}
And here is how I added the UIScrollView to the UIView (whitebackground view) whose name is ForecastView:
_hourlyForecast = [[hourlyForecastScrollView alloc] init:_city state:_state icons:_icons times:_times temps:_temps];
_hourlyForecast.backgroundColor = [UIColor blueColor];
_hourlyForecast.frame = CGRectMake(20, 20, self.ForecastView.bounds.size.width, 70);
[_ForecastView addSubview:_hourlyForecast];
By default, a view will not clip it's subviews. To enable clipping, set the UIView clipsToBounds property, or set it in Interface Builder
(credit to Mugunth for the image)

make a button that moves image

I want to make a button that moves my image one frame height up and if the button is pushed again move the image one frame height back down.
http://imageshack.us/photo/my-images/140/72197925.png/
(Illustration of the solution)
I am trying to use as little code as possible.
UIImage *image = [UIImage imageNamed:#"01bear.png"];
imageView = [[UIImageView alloc] initWithImage:image];
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:applicationFrame];
scrollView.contentSize = CGSizeMake(5760, 1);
[scrollView addSubview:imageView];
[window addSubview:scrollView];
[window makeKeyAndVisible];
scrollView.delegate = self;
scrollView.pagingEnabled = YES;
on button's touchUpInside event you need to change the:
scrollView.contentOffset = CGPointMake(X,Y);//required value to scroll the scrollview
if you only want the imageview to move, you can use:
[imageView setCenter:CGPointMake(X,Y)];//required value
Some questions:
Are you using the scroll view for other things, or just to get your image to move?
Do you want your image view to animate up, then down, or move suddenly?
A scroll view is awfully complex if all you want to do is have your view animate up, then down. To do that, you should look at the UIView class method animateWithDuration:animations: and it's variations.

Resources