# I have a UITableView with custom UITableViewCells. My views are autorotated on orientation as I have implemented the ios6 orientation methods.
# I am not using xib file and drawing all the contents programmatically (imageView,label).
When I rotate my device the tableView and Cells are rotated but cell subviews are not proper in terms of size and position.
# So how to resize the current cells being drawn on the TableView. As the cells are drawn asynchronously and not all at once, how to apply resizing ?
# Do I need to apply AutoResizingMasks or NSLayoutConstraint ? My TabBar and NavigationBar are properly resized but cells are not.
***Plz note: I have not added any block of code, bcoz I simply dnt understand how to proceed as for already drawn cells and those being drawn dynamically after objectForRowAtIndexPath.
I have found the answer. As for orientation in ios6, there are many links for implementing new methods.
Initially my views were not supporting rotation till I found that my tabBarController was a RootViewController for the app so I added (BOOL)shouldAutorotate
{return YES;
} in my subclassed TabBarController class
and in my info.plist added key value pairs for supported interface orientations, this values will be global to the application unless you specify exceptions in current UIViewController via - (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
For implementing rotation in UITableView, I called reloadData(); via using - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self.tableView reloadData];
}
Its not necessary to write a custom UITableViewCell Class, as you can redraw cells in – tableView:cellForRowAtIndexPath: method. As I already had a custom UITableViewCell Class I draw new cells in layoutSubviews(); by getting [[UIApplication sharedApplication] statusBarOrientation] method. If you have any custom UIViews inside the cell you need to redraw the rect to support the landscape mode. Basically I am also supporting ios5 so I am not using AutoLayout via XIB. You can also use autoresizing masks to each subviews as per your layout frames.
reloadData(); is not expensive to memory as you don't call for all the cells # the same time and only the visible cells in the UITableView are redrawn and cells are reused as before.
Related
Using Helixtoolkit you have set up a scene (viewport). Added the camera, default lights, grids, etc. You also added a SortingVisual3D where you add various box elements for example. They are rendered as they are placed in the view. Everything fine.
Now I would like to achieve is to create a new container for 3D objects where my moving gizmo would be placed (every object gets one). If I add gizmo to sorting container, it might not be visible (box overlapping gizmo), so I need a separate container which has to be rendered on top of everything.
How to set container (content) to be rendered on top of everything - regardless of its physical location while still keeping it in the correct 3d space when rotating camera. Something like 3dsmax does (example).
Tnx
Ok, found the solution myself. What you want to do is to make an overlay and transform Point3D to Point and place objects there (a canvas for example).
I have an app that can be rotated, so I need to deal with portrait and landscape orientations. Additionally, users will be allowed to use pinch gestures to change the scale of views. Here is the basic hierarchy of the views.
mainView is a subview of self.view (from the context of the main view controller). It is a UIImageView, although the image part of it is relatively unimportant. In any case, this is the view within which the rest of the views in this discussion are placed as subviews.
The first is what I call the board. It is the view on which items are assembled by the user. These items are themselves image views.
Additionally, there are what I call palettes. These are simply views that can be resized and scaled by the user. Additionally, the image views just mentioned can be dragged from one palette to another or to the board. The palettes can be thought of as work space for the user. When they are finished their work, they place their assembly onto the board.
So far, I've been working with the app where the board is part of autolayout but the palettes are created programatically as needed. This is good because when the user rotates the device, autolayout automatically places the board appropriately. At least it did until I wanted to add pinch scaling to it.
Autolayout has the following constraints set to it in interface builder:
Leading, top, trailing, and bottom all set to superview default.
When the user scales the view, the result is that it sort of sticks to the upper-left corner of the screen. I'd rather have it retain the center.
I tried changing this programmatically by adding the following code to the pinch gesture recognizer for this view:
if (self.pinchView.tag == TAGBOARD) {
[NSLayoutConstraint constraintWithItem:self.pinchView
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.mainView
attribute:NSLayoutAttributeCenterX
multiplier:1.0
constant:0];
}
but this seemed to do nothing. I'm guessing it's because it conflicts with the IB constraints. Is there something else I can do to make this work with autolayout? Or should I just do it all programmatically like I do with the other views?
In this code example, self.pinchView is the view on which the pinch gesture is applied to. For the sake of this discussion, it is what I've called the board. The self.mainView view is its superview.
The part we're not seeing in the code is something like
[self.pinchView addConstraint:yourNewConstraint];
I can see where you create the constraint, but not add it to the view. If you want your constraint to win you'll need to remove the other views or make sure the new constraint has a higher priority.
If your view should be centered, try adjusting the constraints in the storyboard to pin the width and height to the default and then aligning horizontally in the center. That should satisfy autolayout and replicate what you're trying to add, then in your pinch recognizer you can change the constant of the width and height. Be sure to drag your width and height constraints into your controller to create an outlet so that you can adjust them during the pinch gesture.
using iOS 6 MapKit, I would like to define an MKAnnotation (such as a pin, or a custom one) that remains fixed on the center of the map view as the user moves the map around. Once the user stops moving the map, I would like to be able to read the new coordinates of the annotation. How can I do this?
Thanks
The easiest way is to simply add your custom UIView to your MKMapView as a subview. This means when your user moves the map it will stay fixed. You will most likely have to pass through the touch events so that users can move over your custom view but worry about that later.
When your map view stops moving take its center coordinate. The MKMapView can calculate its coordinate based on its center etc [mapView centerCoordinate];
I know this is a bit old but I recommend you DSCenterPinMapView
It is a custom MapView with an animated and customizable center pin useful for selecting locations in map.
You should install the Pod and then, as a solution to your question you should implement the delegate so that you can get the location where pin drops.
pinMapView.delegate = self
extension MyViewController: DSCenterPinMapViewDelegate {
func didStartDragging() {
// My custom actions
}
func didEndDragging() {
// My custom actions
selectedLocation = pinMapView.mapview.centerCoordinate
}
}
I have a collection view whose layout is managed by a UICollectionViewFlowLayout instance. I have a long press gesture recognizer attached to the collection view whose job is to detect if a long press occured within the bounds of one of the cells in the collection view and if so, delete that cell after changing the cell's transform animatedly.
This is the relevant part of the action performed by the gesture recognizer:
UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
[UIView animateWithDuration:2.0 animations:^{
cell.layer.transform = CATransform3DMakeScale(1.0, 0.0, 1.0); // an example animation - squish the cell vertically
} completion:^(BOOL fin) {
//[cell.layer removeAllAnimations];
[self.model.numb3rs removeObjectAtIndex:[indexPath row]]; // update model
[self.collectionView deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]]; // delete item
}];
The problem is that the deletion method seems to perform its own property change/animation on the cell which doesn't gel well with my animation. For instance, in the effect I'm trying to achieve here, once the cell is completely squished vertically, I'd like it not to show itself in the view again, but the deleteItemsAtIndexPaths: call causes the cell's "ghost" to show up and then fade out as the method performs its own transform and opacity animation.
Am I approaching it completely wrong? Possibly the collection view architecture offers a better way to do what I want, rather than explicitly animating the cell and then deleting it like I'm trying?
I'm hoping I might be able to get a quick answer here rather than have to dig into the documentation too deep.
I asked this question on the Apple Developer Forums, and was informed of the
-finalLayoutAttributesForDisappearingItemAtIndexPath:
method which is part of the UICollectionViewLayout class.
Anyway, by subclassing UICollectionViewFlowLayout and overriding this method, I was able to modify the attributes of the cell I was deleting - in particular, the transform.
One thing to note is that this method gets called not only for the cell being deleted but also for cells being shifted from their position during the relayout. But it's simple enough to write code to keep track of the cell being deleted and only modified its attributes.
What is the best way to manage a very large amount of images (10,000+) in WPF? This is for a 2d tile map editor similar to this : http://www.mapeditor.org/ .
At the moment i have a canvas with all tiles as an image and a list box which contains the different images to choose from. Each tile is added to the canvas as children and then stored in a list for later access. You paint into the canvas by setting the Source property of a tile to the one selected in the listbox. It works well with around 50x50 tile maps but anything above that causes loading delays, in general slow application.
Any suggestions on this? Would QT maybe be more suited instead of wpf?
Thanks in advance
Check out Implementing virtualized panel series of articles.
Virtualized panels are efficient, because:
Only the displayed elements (and a few extra around the borders to enable smooth scrolling) are in the memory (and rendered).
Elements are reused, instead of being repeatedly created and discarded - an old cell is simply filled with new content (supplied with new DataContext) and used in new location.
You might also try to use WPF's DataGrid for this, it supports virtualization out of the box and is essentially what are you trying to do.
WPF is certainly able to do this, if implemented properly (if you can do that in JavaScript, you can certainly do it in WPF as well).