UITextView scrolling issue when image is added as a subview - ios

I have a fixed size UITextView and if I add more word's, it will scroll to it's content. I'm adding an UIImage as a subview in UITextView. If there are more comment's I cannot scroll UITextView to see the image. Can we set the content height of uitextview to solve this issue?

UITextView is not designed to receive a subview like that, and it won't scroll it correctly. You need to add both as subviews in a UIScrollView, which should auto-behave like so:
Swiping should first scroll the view where the touchDown event began (i.e., your UITextView)
When that view has no more to scroll, the event should bubble up to the UIScrollView itself, bringing up your UIImage.
If you don't like this behavior then you can synchronize scrolling as you prefer by calculating the height of your text inside your UITextView bounds, using:
CGSize size = [myText sizeWithFont:myFont forWidth:myFontWidth.0 lineBreakMode:UILineBreakModeWordWrap];

Related

How to stop moving UIVIew on keyboard appearing in iOS?

Whenever I click on a UITextField, my UIView will move up. How can I stop this?
There could be a chance of one of below.
If UIView is inside(contained) by ScrollView, then set the contentSize to have more height CGSize siz=sv.frame.size; siz.height+=300;sv.contentSize=siz; where 300 is keyboard height.
If there is some code to handle keyboard sizing then search for UIKeyboardDidShowNotification and comment the lines with addobserver, removerobserver in them

Let uiscrollview dynamically adjust to uitextview height

My structure consist of
- uiview
- scrollview
- contentview
- uitextview
- uibutton
What I'm trying to achieve is to adjust the height of scrollview according to textview height or content. Textview gets its text on run accordingly. So when i have a long text in my textview, scrollview adjusts itself so all textview's content is visible by scrolling.

Scrolling a UITextview with UIScrollview

So I've created an UITextView and put it inside an UIScrollView. However, I disabled scrolling for UITextView, so I was wondering is it possible for me to scroll the textview at the same time while I'm scrolling through my UIScrollView?
I'm not sure if someone has already asked something like this, I tried to search through the site and couldn't find any topics related to my problem. If there's an existing post like this I would appreciate it if someone plink me to it.
UIScrollView is a scrolling UIView. So you need just to add the UITextView to the scroll view as a subview and it will scroll with it, basically something like this:
UIScrollView *scrollView = [UIScrollView alloc]initWithFrame:CGRectMake(0,0,320,460)];//adjust the frame to fit your needs
scrollView.contentSize = CGSizeMake(400, 600);//make sure the size in contentSize is bigger than the size of the scrollView frame: (400, 600) is bigger than (320, 460), otherwise the scroll effect won't be performed
UITextView *textView = [UITextView alloc]initWithFrame:CGRectMake(0,0,200,400)];//adjust the frame to fit your needs
[scrollView addSubview:textView];//need to add the text view as a subview
[self.view addSubview:scrollView];

UIScrollView with variable height

I have a scrollView with a UIView as subview, which in turn has many subviews, one of which is a textView with variable height. This is the hierarchy of views:
-UIScrollView
- UIView
-UITextView with variable height
-UImages
As can dynamically vary the height of the UIView and finally the scrollView based on the length of the content?
When the user edits your UITextView field, get its bounds height and recalculate the overall size of you scrollable view, then set UIScrollView's contentSize property.
You can detect the end of editing on a UITextView object by means of its UITextViewDelegate textViewDidEndEditing: method.

UIScrollView keep scroll rect while resizing

I have got a UIScrollView with a UIImageView as subview. The contentSize of the ScrollView has been set to the size of the UIImageView.
I implemented zooming and scrolling of the UIImageView.
I need the UIScrollView to keep the scroll rect when I change its frame (proportionally).
How is this done?
My problem is, whenever I change the frame of the UIScrollView the visible rect of the UIImageView changes.
Thanks!
If I understand your problem correctly, you want to shrink the frame of the scroll view without changing what you are able to see inside of the scroll view. You can do this in the following way:
Create a new UIView and set its frame to the position and size that you want to see the content of the scroll view. Turn on the clips to bounds on that view, view.clipsToBounds = yes. Add the scroll view as a subview to the view you created. [view addSubview:scrollview]. Turn clips to bounds off on the scrollview, scrollview.clipsToBounds = no.
Hope that helps.

Resources