Is it possible to have 3 scroll views lets say the middle is the main where is user find objects inside, then user can drag any item and drop it to the right scroll view or left scroll view so that's object will be removed from the middle and dropped either right or left depends on the uses and suppose the user dropped it to the left thus system should add new object to the left scroll view but when the user remove this object and return back to the main (middle) preferred to dropped and added in the same old index if the object was number 2 then the object will added and dropped at index 2 ..etc.
Could you help on this to make this functionality ?
Let's call the items model1 ... model3;
#property (nonatomic, strong) NSMutableArray *mainArray;
#property (nonatomic, strong) NSMutableArray *leftArray;
#property (nonatomic, strong) NSMutableArray *rightArray;
#property (nonatomic, strong) UIScrollView *mainView;
#property (nonatomic, strong) UIScrollView *leftView;
#property (nonatomic, strong) UIScrollView *rightView;
You need make a model class such as ItemModel inherit UIView or NSObject, in ItemModel.h make some property(what property you need and a property about which UIScrollView contains this model)
First, put all models in the mainView's datasourcemainArray, display models in your self.view and call self.view bringSubviewToFront: and give all models a UIPanGestureRecognizer and a method to respond to UIPanGestureRecognizer so you can drag them.
This is the most important part:
Because you want all models to be contained by three UIViews, you must calculate the models frame between self.view.frame and the three UIView frames relationship. In fact, all modelViews is contained by self.view, but when visually displayed, all modelViews is contained within UIScrollViews.
Second, you already have the frame of three UIView, when you drag model, you can get CGPoint about the location of the drag, then call the method CGRectContainsPoint(CGRect rect, CGPoint point), so you can get any view that contains the point you drag.
For exexample, you drag model1 from mainView to leftView, you can get a YES from CGRectContainsPoint(leftview.frame, point), then remove the model1 from mainArray and put model1 in leftArray, meanwhile you need to re-layout the three UIViews.
here is my share URL for the gif:https://pan.baidu.com/s/1slFBva9
Related
I have a problem about Xcode storyboard and dynamically showed views.
I have 3 vertically aligned views in my storyboard and each one is linked with each other with top-bottom relationship with constraints
However during runtime I want to hide the 2nd view and replace its place with the 3'rd view (which is a tableview) and to fill the both 2nd and 3rd places I'm trying to extend the height of tableview.
However I cannot succeed. I have tried lots of things but closest thing I get is to transform the 3rd view to 2nd place but the height remains the same
My latest code is in below
if (status) {
self.filterView.hidden = NO;
self.contentTable.frame = contentTableFrame;
} else {
self.filterView.hidden = YES;
CGFloat predictedHeight = self.contentTable.frame.size.height+(self.contentTableFrame.origin.y-self.filterView.frame.origin.y);
self.contentTable.transform = CGAffineTransformMakeTranslation(0, self.filterView.frame.origin.y-self.contentTable.frame.origin.y);
for (NSLayoutConstraint *constraint in self.contentTable.constraints) {
if (constraint.firstAttribute == NSLayoutAttributeHeight) {
constraint.constant = predictedHeight;
}
}
}
You can also find the screenshot of the 3rd view's constraints. What should I do to fix that? Does anyone have any idea about it?
I also have another solution to this problem . But I've another problem on that too.
When I executed the below line of code my 3rd view move to 2nd view's place but its height remains the same so on the bottom of the page it happens to seems a blank space.
self.contentTable.transform = CGAffineTransformMakeTranslation(0, self.filterView.frame.origin.y-self.contentTable.frame.origin.y);
In order to fix that I've tried to change its height(with .frame = CGRectMake(.....) )
but it didn't work.Then I've tried to scale the 3rd view(which is a tableview) and it succeed but because I've scaled it all the cells inside the tableview scaled too and the visual appearance of the table has broken. So I couldn't able to find a solution to that problem.
It seemed like a challenge.
Thanks
Sorry it is in objective-c.
I get the top contraint from the TableView (Storyboard). When I hide the topView, I get the height of my topView and change the top constraint constant. You can see it in #IBAction. Finally, the tableView is stretched and takes the space left from the topView. Is that what you were looking ?
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
#property (weak, nonatomic) IBOutlet UIView *topView;
#property (weak, nonatomic) IBOutlet UITableView *tableView;
#property (weak, nonatomic) IBOutlet NSLayoutConstraint *topTableViewConstraint;
- (IBAction)pushTest:(id)sender;
#end
ViewController.m
- (IBAction)pushTest:(id)sender {
if (self.topView.hidden) {
self.topTableViewConstraint.constant = 0;
}else{
self.topTableViewConstraint.constant = -self.topView.bounds.size.height;
}
self.topView.hidden = !self.topView.hidden;
}
you can hide filterview but you can't replace it by tableview.
if you want to replace it by table view.You need to use method BringSubviewToFront for That Tableview.it will bring that tablview to front and set filterview to back which is hidden for ui.
I have a custom tableViewCell class that has a UIImageView as an IBOutlet.
#property (nonatomic, weak) IBOutlet UIImageView * waveformImageView;
I also have two view controllers: one with a tableView and one without a tableView.
I need to know the height and width of this UIImageView to send to another class to do a calculation in my NON tableView view controller
I tried doing the following in my header file of my view controller (view controller without a tableView)
#property (nonatomic, strong) OSAudioTableCell * tableCell;
and then accessing the UIImageView property by doing the following in one of my methods:
self.tableCell = [[OSAudioTableCell alloc] init];
[self.waveView setSize:self.tableCell.waveformImageView.bounds.size];
This is all done in my view controller that doesn't contain a tableView. I'm pretty sure I'm doing this wrong since the width and height are coming out as zero. I can get these values fine within my view controller which contains my tableView.
Came up this question and did some quick experiments without no luck.
Basically, I made a simple single view project where the top view controller is a UITableViewController. For simplicity, I set the table view content to be "Static Cells". The table cell was a custom subclass of UITableViewCell, like this
#interface TopTableViewCell : UITableViewCell
#property (strong, nonatomic) IBOutlet UILabel *label;
#property (strong, nonatomic) IBOutlet TableCellBottomView *bottomView;
#end
Both the properties were wired through control dragging. The TableCellBottomView is just a custom subclass of UIView like this
#interface TableCellBottomView : UIView
#end
Now I add a label inside this TableCellBottomView like the following picture showing
Can I wire this bottom label inside to my TableCellBottomView? Control dragging did not work for me here. I certainly could have added it programmatically inside TableCellBottomView.m. But if i could wire it here, it would be quite convenient, since I could also add a lot of other components and arrange them visually. Thanks!
You may set a tag for the label in Xcode and fetch the UILabel based on the tag wherever you need it:
If you use dynamic cells, you can do this in tableView:cellForRowAtIndexPath:. Alternatively wire the cell to a property and then use that property to fetch it:
((UILabel*)[cell viewWithTag:1]).text = #"Some text";
I don't know why Xcode won't allow you to drag from your label to the bottom view .h file, but you can do it another way. Add the IBOutlet property to the .h file, then drag from the littler open circle to the left of the #property to your label in the storyboard, and that should work.
I originally had a normal view with a bunch of stuff in it, and I want that view to be an UIScrollView, so I created a new ScrollView and dragged everything over. The view is not scrolling.
After looking around - I unchecked use autolayout, but that didn't work. I also realize that this could be solved by setting contentSize, but I have access to this view through a variable that is of type UIView, and not UIScrollView. In other words I would be doing -
self.someController.view.contentSize = //something
where self.someController.view is only an UIView and contentSize is not a property of UIView(or at least that's what I'm seeing- I get compiler warnings).
Why is this scroll view not scrolling?
EDIT -
So I stupidly forgot I can cast - I did that, but it's still not working -
UIScrollView* basicCardView = ((UIScrollView *)self.detailController.view);
basicCardView.contentSize = CGSizeMake(basicCardView.frame.size.width * 12,
basicCardView.frame.size.height);
You need to connect your scrollview to Iboutlet var in .m .
Create var in your interface:
IBOutlet UIScrollView *scrollview;
And connect to your scrollview in storyboard, then you can set contentsize.
[scrollview setContentSize:CGSizeMake(2000,200)];
Elto has it correct. To elaborate: In your view controller .m say it's called MyViewController:
#interface MyViewController ()
#property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
#end
Go back to storyboard, select your view controller and select the connections tab (last one on the upper right). You should now see an outlet called scrollView. Drag a connection from that outlet to the scroll view that you added to the scene.
Now the content size code can be written. Just to get it working, use large constants in content size, like:
self.scrollView.contentSize = CGSizeMake(1000, 1000);
The size you're setting in the post (on the wrong view) looks like it's just the size of one of the subviews. You want the content size of the scroll view to be more like a multiple of the scrollView's size. You want the rectangle it can scroll within to at least encompass the frame (not the bounds) of every subview it contains.
I have a static table, one cell has multiple views that I would like to add subviews. Each view has a class (MHRotaryKnob) assigned.
What I can't figure out is how to ID each view in the cell so I can addSubView.
I have set up the table within StoryBoard.
Give your Viewcontroller an IBOutlet-Property for a UIView like so:
#property (nonatomic, strong) IBOutlet UIView *myView;
then connect those to your desired view in storyboards.
now you can address this view in code like this:
[self.myView addSubview:subView];
Thats probably easier than messing with ids or tags.
If you have problems, this will help you:
http://klanguedoc.hubpages.com/hub/IOS-5-A-Beginners-Guide-to-Storyboard-Connection
EDIT:
If you want ta add a subview to a MHRotaryKnob, you can just go the other way around:
#property (nonatomic, strong) IBOutlet MHRotaryKnob *myKnob;
and then, assuming that MHRotaryKnob is a direct or indirect subclass of UIView, you can add the subview:
[self.myKnob addSubview:subView];