I have a UIImageView (imageView) being the subView of the UIScrollView (scrollView). The scrollView is set only for pinching the showed image from imageView. And I have a small UIImageView (iconView) which is the subView of imageView. So the relationship is like:
UIView
|_____ UIScrollView ( scrollView )
|_____ UIImageView (imageView)
|______ UIImageView(iconView) .
I need to touch and move the iconView but I am confused with this two methods I found.
Can I simply use the "hitTest:withEvent:" method to work this out and how to use hitTest ?
Or Should I override "UITouchesBegan:withEvent:" "UITouchesMoved:withEvent:" "UITouchesEnd:withEvent:" ? and how to use it?
You should use the 2nd method.
Subclass the UIView class and create CustomView. Define iconView as CustomView.
In CustomView define the 3 delegates to the desired behaviour:
UITouchesBegan:withEvent:
UITouchesMoved:withEvent:
UITouchesEnd:withEvent:
Hope this helps
Related
I have an ViewController with a View called MasterView(it's the first UIView of the ViewController)
Inside the MasterView, I have a UIImageView, both views have a width of 320, take a look on the images below:
But when I try to get the image size programmatically, I use the following code:
/* imagemPrincipalCabeca is an IBOutlet connected to the UIImageView */
print("master uiview frame: \(view.frame.width)")
print("master uiview bounds: \(view.bounds.width)")
print("subview uiimageview frame: \(imagemPrincipalCabeca.frame.width)")
print("subview uiimageview bounds: \(imagemPrincipalCabeca.bounds.width)")
I got the following text on the console:
master uiview frame: 375.0
master uiview bounds: 375.0
subview uiimageview frame: 320.0
subview uiimageview bounds: 320.0
If the UIView width and the UIImageView on my code is 320. Why the view.frame.width results in 375 ?
I know the device screen in pixels is 375 and device points in screen is 320, but why I got different values when I use the code above?
Based on the #SWeeper comment.
I test the viewDidAppear method and viewDidLayoutSubviews method.
The viewDidAppear method didn't work for me,
but the viewDidLayoutSubviews method WORKED for me.
I use a ContainerView, maybe this is the reason why I need to use the viewDidLayoutSubviews method to make my code get the correct width of my view.
Using storyboard i want to add UITextview in the UIScrollview and the scroll the TextView in the in the screen. please help me...
scroller.contentSize=CGSizeMake(320,846);
[scroller setScrollEnabled:YES];
int GetIndex = [GetSelectedIndex intValue];
label = [firstheading objectAtIndex:GetIndex];
labelheading.text=label;
textviews = [firstdesc objectAtIndex:GetIndex];
textview.text=textviews;
[scroller addSubview:textview];
NSLog(#"textview:%#",textview);
NSLog(#"image:%#",getimage);
Just a suggestion, you could try adding a UIView on your ViewController first.
Then drag the UIScrollView into your UIView.
Then drag a UITextView into that.
I have this arrangement in a Storyboard - because I have an image in the top level UIView as well as the UIScrollView
I have a CALayer (CAGradientLayer) added as a subview of a UIImageView. I have successfully added it as a sublayer of the UIImageView, however on orientation I'd like to adjust the layer's width. How can I do so? I tried the following code without any success:
- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self.imageOverlay setFrame:self.backgroundImageView_.bounds];
[self.gradientOverlay setFrame:self.view.bounds];
}
Are you supporting < iOS 5? You can override the viewWillLayoutSubviews method on your view controller and try setting the frame there. Otherwise, create a view subclass to use as the container of the gradient layer and resize the layer in layoutSubviews.
I have a UIView with an alpha of 0.5 which I add as a subview to my primary view in order to gray-out everything else. I want to add an additional UIView to this gray UIView as a subview - the problem is that when I do this, my newly-added subview is also partially transparent.
Is there any way to make a subview "ignore" the alpha value of its superview and be itself fully opaque?
Set the UIView background color alpha not it's alpha directly.
Objective-C
UIView *view;
...
view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.6];
It's not the same as:
view.backgroundColor = [UIColor blackColor];
view.alpha = .6;
Swift
view.backgroundColor = UIColor.black.withAlphaComponent(0.6)
No, not really. What you want is to take your overlay view, and make it just have a clear background color. As a subview of that new overlay place your view that will grey things out. And as a sibling view to that put your view you want to be opaque.
[OpaqueView] [DimmingView]
| |
[OverlayView]
Don't put it inside the semi-transparent view. Make it a sibling to semi-transparent view and put it over it using z-ordering.
This will only work if you have any image on the background.
Instead of reducing the alpha of UIView, add an UIImageView on that view and then reduce the alpha of the UIImageView.
now add your subviews on the UIView.
your subviews will not take the alpha property anymore.. :)
No, any view will inherit the opacity of its parent.
I'm trying to draw in a scrollview on top of an image using multi-touch. The circles are actually drawn, but under the image. In my code I currently create a custom ScrollView:
#interface AppScrollView : UIScrollView {
//objects to draw circles
NSMutableDictionary *circlesInProcess;
NSMutableArray *completeCircles;
}
#end
In my AppScrollView.m I override touches commands to store touches and add a
(void)drawRect:(CGRect) rect
method to draw the circles in the scrollview. I also include
[self setNeedsDisplay]
to display the circles. In my app controller, I declare the new custom scrollView object:
IBOutlet AppScrollView *scrollView;
Later I add an image to the scrollView using:
[scrollView addSubview:myImage];
The image is visible, but when I try to draw circles on top of it, they are drawn under the image. Let me know if you have any suggestions?
Suggestion: draw the image onto your scrollview (instead of adding the image view as a subview) and then draw the circles on top of that.
In your code check where did you add you custom scrollview. Is it added after imageView is added or before.
You scrollView should be on top of imageView.