mercredi 25 mars 2015

Rendering Text after Scaling and Rotating UITextView

Problem


After scaling and rotating a UITextView using gestures, the text is sometimes fuzzy because the transformations are applied to the rasterized bitmap.


Proposed Solution


Once the gesture is complete, I need to return the transform to the identity transform, resize the frame based on the scale, resize the font based on the scale, and then re-apply the rotation transform.


Implementation Attempts



// Store original center before making changes

CGPoint originalCenter = textView.center;

// Restore transform to identity (frame property is invalid while transform is not identity)

[textView setTransform:CGAffineTransformIdentity];


// Attempt 1 - sizeThatFits /////////////////////////////////////////////////////////////////

// Scale font

[textView setFont:[UIFont fontWithName:textView.font.fontName size:textView.font.pointSize*scale]]; // scale refers to the scale of the pinch gesture that just ended

// Set frame to sizeThatFits

CGSize size = [textView sizeThatFits:maxSize]; // maxSize begins with the view frame size and is scaled at the end of each pinch gesture
[textView setFrame:CGRectMake(0, 0, size.width, size.height)];

// Restore Center

[textView setCenter:originalCenter];

// Re-apply rotation

[textView setTransform:CGAffineTransformMakeRotation(rotation)]; // refers to the total rotation from all rotation gestures


// Attempt 2 - manually scale /////////////////////////////////////////////////////////////////

// Scale font

[textView setFont:[UIFont fontWithName:textView.font.fontName size:textView.font.pointSize*scale]];

// Scale frame

[textView setFrame:CGRectMake(0, 0, textView.frame.size.width*scale, textView.frame.size.height*scale)];

// Restore Center

[textView setCenter:originalCenter];

// Re-apply rotation

[textView setTransform:CGAffineTransformMakeRotation(rotation)];


Notes


Everything I try almost works. In some cases, especially after multiple gestures (compounding the error), the text doesn't fit exactly right and will cause line breaks where there were none before.




multiples device without autolayout

Hello everyone I have Now Xcode 6.2 I have two projects (project A) and (project B). In the two projects the auto layout and auto layout class are disabled. The two projects have storyboard for iphone 5. The problem is that the (project A) I can run on iPhone 5, iPhone 6 and iPhone 6+ and everything looks perfect like auto layout is automatic.


The (project B) I can run on iPhone 5 is ok but on iPhone 6 and iPhone 6+ I have too much difference of size by the difference of the device. It only works for iphone 5. The only difference is that (project A) is made with Xcode 5 but now is running with xcode 6.2


(project B) is made with Xcode 6 but now is running with xcode 6.2


What is the difference? Why is this happening and what I can do to make the (project B) run like (project A) without autolayout? Note that the (project B) has many elements ( Buutons, View , Label, etc )


Appreciate your advice. Thank you in advance.




Opening about part of setting in iOS with Swift

i'm trying to make an app who open Settings app in a specific section (About). I already use this part of code made with swift but i can't control in how section in settings i have access.



override func viewDidAppear(animated: Bool) {
var alertController = UIAlertController (title: "Title", message: "Go to Settings?", preferredStyle: .Alert)

var settingsAction = UIAlertAction(title: "Settings", style: .Default) { (_) -> Void in
let settingsUrl = NSURL(string: UIApplicationOpenSettingsURLString)
if let url = settingsUrl {
UIApplication.sharedApplication().openURL(url)
}
}

var cancelAction = UIAlertAction(title: "Cancel", style: .Default, handler: nil)
alertController.addAction(settingsAction)
alertController.addAction(cancelAction)

presentViewController(alertController, animated: true, completion: nil);}


Is there any solution to open settings right in the About section ? Thanks




ios swift - issues with keyboard (cover up textfield, etc..) and some other widgets

I'm an android guy and have recently started to learn swift.


I have went through the tutorial about the structure of swift, but what's really giving me headache now is the UI widgets




  1. keyboard covers up textfield. how can I make it so view would get pushed up if textfield is covered but does nothing when textfield is visible. the example I found here would push the view up or down to be exactly right above the keyboard, but pushing the view down isn't what I want.




  2. how can I have the error icon on the right within the textfield like this? and also how to add an additional row of navigation right above the keyboard to allow user go backward/forward and Done enter image description here




  3. I found a Date Picker in Object library, but it takes a lot of space. What I want is like the screenshot below. it pushes the view up when user click on something then disappear when done. and also the same question on how to have the additional nav bar right on the top of keyboard enter image description here




  4. I don't know if it's going to be the same thing as Date Picker. I also want a list show up at the bottom when event is triggered.




Can someone please please help me? or direct me to the right article. I found myself having really hard time on UI when coding in swift :(




Website looks bad on iPhone 4

http://cheese-milk.ru/


Did a mobile compatible (as I thought) website. It looks fine on all mobile devices (Android, Windows, iPhone 5-6), but the text on the last to bottom block slides onto the contact block in iPhone 4.


I am really confused as in the Chrome mobile development it looks fine, but as I was bragging I did a great website, someone with a phsycial iPhone 4 came up to me and showed me the problem.


It seems as if the text does not size up to the display.


I hope this is not a "narrow, single-use" problem, because I don't really know where to dig.




Programmatic Device Specific iOS Constraint is nil

I came across an interesting problem that only arises on iPhone 6/6+ and iPad mini with retina display.


In the following code:



- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if(self.seeMoreContents)
{
BOOL isText = [self.seeMoreContents isText];
self.imageView.hidden = isText;
[self.textView removeConstraint:self.textHeightConstraint];
[self.textWrapperView removeConstraint:self.textWrapperHeightConstraint];

if (!isText)
{
__weak FCSeeMoreViewController *weakSelf = self;
[self.imageView setImageByFlashcardSide:self.seeMoreContents completion:^(BOOL preloaded){
weakSelf.imageView.center = CGPointMake(weakSelf.view.frame.size.width / 2, weakSelf.view.frame.size.height / 2);
[weakSelf.scrollView setContentOffset:CGPointMake(0, 0)];
}];
}
}
}


- (void)viewDidLayoutSubviews
{
if ([self.seeMoreContents isText])
{
self.textView.text = self.seeMoreContents.text;
self.textView.font = self.fontForContents;

self.textWrapperView.hidden = NO;
[self.textView sizeToFit];
CGFloat height = self.textView.frame.size.height;
[self updateView:self.textView withConstraint:self.textHeightConstraint ofValue:height];
[self updateView:self.textWrapperView withConstraint:self.textWrapperHeightConstraint ofValue:height + self.wrapperMargin];

[self.scrollView setContentSize:CGSizeMake(self.textView.frame.size.width, height + self.scrollTextMargin)];
[self.scrollView setContentOffset:CGPointMake(0, -self.wrapperScrollVerticalConstraint.constant)];
}
[super viewDidLayoutSubviews];
}

- (void)updateView:(UIView*)view withConstraint:(NSLayoutConstraint*)constraint ofValue:(CGFloat)value
{
constraint.constant = value;
[view addConstraint:constraint];
}


By the time the two messages of udpateView get passed, the constraints have become nil. I could attribute this to weird garbage collection behavior, but it only happens on iPhone 6/6+ and mini retina iPad.


I have changed this whole controller to work better and to not to programmatically set constraints, but I want to know how/why this can happen on specific devices. Any insight would be greatly appreciated.




Building project with Xcode 6 (iOS 8 SDK) causes landscape rotation rendering issue on iPad

We have a project that behaves as desired when built using Xcode 5.1.1 (iOS sdk 7.2), but when build using Xcode 6.2 (iOS sdk 8.2) there is a rotation rendering issue on the iPad. On the iPad our app only supports landscape left and landscape right. When you rotate from one to the other, on the rotation animation the screen rotates from upside down to right side up, but when it does this it lands in the wrong position. (The bottom-left corner of the screen ends up approximately 200 pixels up from the bottom and an equal number of pixels inset from the left.)


This may also happen on iPhone, but on iPhone we only support portrait so rotation isn't an issue.


Has anyone else seen then behaviour and know what the root cause may be?