sberrevoets / sdcalertview Goto Github PK
View Code? Open in Web Editor NEWThe little alert that could
License: MIT License
The little alert that could
License: MIT License
Hi,
I am getting issue in ios 8 . in ios 7 it works perfectly. I am attaching screen shot .
i have also post my question on stackoverflow https://stackoverflow.com/questions/25933306/sdalertview-buttons-are-not-visible-in-ios-8..
Thanks in advance
Kalpesh
The alert currently doesn't rotate when the device is rotated or already in landscape mode when it is shown.
When an alert is modified in a way that it changes the view hierarchy (for example, changing the alertViewStyle
to include a text field where previously it didn't) currently causes a crash because the alert tries to add constraints to views that aren't part of the view hierarchy.
The view hierarchy is built exactly once, when it is sent show
(or showWithDismissHandler:
), so any view hierarchy changes after that will result in a crash.
An obvious workaround until I fix this is to make sure the view hierarchy doesn't change after calling show
.
Hello,
I wonder if it's possible to change the width of the SDCAlertView. Here my piece of code:
_alertView = [[SDCAlertView alloc] initWithTitle:@""
message:@""
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 600, 600)];
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[webview loadHTMLString:htmlString baseURL:baseURL];
[webview setBackgroundColor:[UIColor clearColor]];
[webview setOpaque:NO];
[webview setDelegate:self];
webview.scrollView.scrollEnabled = TRUE;
webview.scalesPageToFit = TRUE;
[webview setTranslatesAutoresizingMaskIntoConstraints:NO];
[_alertView.contentView addSubview:webview];
[webview sdc_pinWidthToWidthOfView:_alertView.contentView];
[webview sdc_pinHeightToHeightOfView:_alertView.contentView];
[webview sdc_horizontallyCenterInSuperview];
[webview sdc_verticallyCenterInSuperview];
[webview sdc_pinHeight:600];
[webview sdc_pinWidth:600];
[_alertView.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[webview]|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(webview)]];
[_alertView show];
return YES;
The hight is ok: 600 pixels, but the width is all the time 270 pixels.
Could you please explain why I can't change the width ?
Thank you so much, and thank you for this beautiful library! ;)
Regards,
Christophe.
Using SDCAlertView as follows, the controller that presents the alert view returns shouldAutoRotate
as 'NO', however SDCAlertView sill rotates.
Is there an easy way to turn this off?
Its not possible to use SDCAlertController, as the view is being presented as follows:
[self presentViewController]
except it has a custom animation on presentation, and uses UIToolbar to give a real-time iOS blur on the camera feed.(seems SDCAlertController doesn't like the above), but SDCAlertView is happy enough, except for the minor issue of unwanted auto-rotation.
Presenting Controller
The window has been given a root view controller, in this case a dedicated one, with its view having containers matching the diagram below.
willMoveToParentController
, etc) when presenting dismissing contained views.The implementation of shouldAutoRotate in the custom root controller is:
- (BOOL)shouldAutorotate
{
BOOL shouldAutoRotate = NO;
if (_overlayController) {
if ([_overlayController isKindOfClass:[UINavigationController class]]) {
shouldAutoRotate = [((UINavigationController *)
_overlayController).topViewController shouldAutorotate];
}
else {
shouldAutoRotate = [_overlayController shouldAutorotate];
}
}
else {
UIViewController *topController = _navigator.topViewController;
shouldAutoRotate = [topController shouldAutorotate];
}
return shouldAutoRotate;
}
. . . the above autoRotate works as expected everywhere except for the SDCAlertView that is being presented as described. Adding a debug shows that:
shouldAutoRotate
returns the auto-rotation of _overlayController.topViewController, which is 'NO'. Yet auto-rotation still happens.The behavior of showing several alerts at a time is different from UIAlertView's
I want to double check that the issue I'm seeing isn't just restricted to the simulator and, if verified, we need to file a Radar because I'm pretty sure it's subtle enough to not have been detected by anyone else. After all, who else stares at their monitor for extended periods watching UIAlertViews
animate in and out, etc? Exactly.
Steps:
This is a regression that causes the apparent color of the alert to be several shades darker than it otherwise would've been on iOS 7.0.x. This makes the contrast between the alert and its dimming/backdrop view somewhat lower, which indicates that this is likely a regression rather than expected behavior. Also the fact that the transition from the "lighter" state to the "darker" state is extremely abrupt.
If this is confirmed, a Radar should be filed and immediately duped.
I had two cases where SDCAlertView was not dismissing properly. Specifically, it wasn't reverting back to the correct key window. One case was when an SDCAlertView was presented as a result of a button selection in an UIActionSheet. The other was a SDCAlertView presented in viewDidAppear: in a modal view controller (which was contained in a UINavigationController). I tracked it down to -[SDCAlertViewCoordinator init] when it captures a reference to _userWindow. In one of my cases, the window it was capturing was an instance of _UIAlertOverlayWindow. I replaced the said line with:
_userWindow = [UIApplication sharedApplication].keyWindow;
if (![_userWindow isMemberOfClass:[UIWindow class]])
_userWindow = [UIApplication sharedApplication].windows[0];
Just what the title says. No buttons show up on iOS 8, so you get stuck with the alert open without possibility of closing it.
Step 1: Set the alertViewStyle property to SDCAlertViewStylePlainTextInput or SDCAlertViewStyleLoginAndPasswordInput.
Step 2: Turn the iPad simulator to landscape mode.
Step 3: Tap to show the alert view.
Step 4: Tap the textfield in the alert view.
Now you can see the alert view position is not correct.
PS: I use the iOS7 simulator.
On iOS7 I'm trying to add a view as a centered subview of the content view.
The auto layout is being ignored for whatever reason and the view is being added to x=0 on the contentview.
My code looks like this:
_emptyFolderProgressDialog = [SDCAlertController alertControllerWithTitle:NSLocalizedString(@"Emptying Deleted Items", nil)
message:nil
preferredStyle:[UIDevice isIos7] ? SDCAlertControllerStyleLegacyAlert : SDCAlertControllerStyleAlert];
IndeterminateProgressView *progressView = [[IndeterminateProgressView alloc] initWithStyle:progressViewStylePurple];
[progressView setTranslatesAutoresizingMaskIntoConstraints:NO];
[progressView startAnimating];
[_emptyFolderProgressDialog.contentView addSubview:progressView];
[progressView sdc_horizontallyCenterInSuperview];
[progressView sdc_verticallyCenterInSuperviewWithOffset:kProgressDialogVerticalOffset];
But what I am getting on screen is this shown below.
On iOS8 this problem does not exist, and the progress indicator is rendered in the center of the view.
When calling -[SDCAlertView dismissWithClickedButtonAtIndex:animated:]
, the animated argument is ignored and alerts are always dismissed with animation.
The status bar tint color changes to back when an SDCAlertView is shown. After it is dismissed, the status bar tint color is not reverted back to white.
Causes no discernible problem other than error being logged.
<<<< (61 seconds after request)
2014-10-21 11:13:15.873 Infiniti[739:148251] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x17583480 SDCAlertLabel:0x17677250'The operation couldn\U2019t be...'.firstBaseline == SDCAlertLabel:0x17676bf0'Error'.lastBaseline + 18>",
"<NSLayoutConstraint:0x1767f620 SDCAlertLabel:0x17677250'The operation couldn\U2019t be...'.firstBaseline == SDCAlertLabel:0x17676bf0'Error'.lastBaseline + 18>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17583480 SDCAlertLabel:0x17677250'The operation couldn’t be...'.firstBaseline == SDCAlertLabel:0x17676bf0'Error'.lastBaseline + 18>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
This one seems to occur when I try to manually dismiss an alert that has already been programmatically dismissed, but the UI hasn't caught up yet.
The code is below. Wire this up to any button in your UI, and then immediately try to close the first alert before it disappears. This locks up the entire UI.
SDCAlertView* alert1 = [[SDCAlertView alloc] initWithTitle:@"Alert 1"
message:@"This one will be immediately dismissed, but if I hit the cancel button on it first, it will ruin everything."
delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
SDCAlertView* alert2 = [[SDCAlertView alloc] initWithTitle:@"Alert 2" message:@"This one should remain up."
delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[alert1 show];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[alert1 dismissWithClickedButtonIndex:0 animated:NO];
[alert2 show];
});
Note that I can only reproduce this if animated is NO in the programmatic dismissal.
I met two issues with following code:
#import "ViewController.h"
#import "SDCAlertView.h"
@interface ViewController ()
@property(strong, nonatomic) SDCAlertView *alert;
@end
@implementation ViewController
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
_alert = [[SDCAlertView alloc] initWithTitle:@"title"
message:nil
delegate:nil
cancelButtonTitle:@"cancel"
otherButtonTitles:@"ok", nil];
[_alert showWithDismissHandler:^(NSInteger buttonIndex)
{
// crash if use -1 as button index
NSLog( @"buttonTitleAtIndex = %@", [_alert buttonTitleAtIndex:buttonIndex] );
}];
[self performSelector:@selector( onTest ) withObject:nil afterDelay:1];
}
- (void)onTest
{
[_alert dismissWithClickedButtonIndex:0 animated:NO]; // crash if use -1 as button index
// will see constraint warning here in Xcode console, debug mode
_alert.message = @"message";
[_alert show];
}
@end
On iOS7 I am unable to dismiss the SDCAlertController with the same code that works on iOS8.
The dismiss code looks as follows:
[self.emptyFolderProgressDialog dismissWithCompletion:^
{
// some code
}];
What I'm finding is that this dismissWithCompletion looks like this:
But the self.presentingViewController is nil - hence nothing is dismissed.
I am showing the SDCAlertController using this code:
_emptyFolderProgressDialog = [SDCAlertController alertControllerWithTitle:NSLocalizedString(@"Emptying Deleted Items", nil)
message:nil
preferredStyle:[UIDevice isIos7] ? SDCAlertControllerStyleLegacyAlert : SDCAlertControllerStyleAlert];
[self.emptyFolderProgressDialog presentWithCompletion:nil];
Showing the SDCAlertView works fine (apart from the layout issue I opened) but it's not possible to dismiss on iOS7.
If only a custom view is used and title/message is set to nil, the separator above the buttons (I am using two buttons, cancel and ok) is not shown. If I add a title and/or message, the separator is displayed correctly.
When SDCAlertView is shown, show UIAlertView. Now 2nd alert is blocked.
could u pls pay attention to it?
UIAlertView, on the other hand, dims but does not black out the status bar.
Not sure if this is a known limitation of SDCAlertView, or just a bug.
AFAIK the default iOS component does not.
I've got an alert with alertViewStyle set to UIAlertViewStylePlainTextInput. Its working fine for iOS7 but in iOS8 its positioning the alert off the screen (only in landscape mode). This may be fixed in the gold master but I thought I would mention it.
It could be beneficial, especially when using the contentView
, to have access to the width of an alert through a constant. This constant exists (SDCAlertViewWidth
), but only in SDCAlertView_Private.h and not in the normal SDCAlertView.h.
If an alert is dismissed, but kept on the heap, the visible
property is still set to YES
.
Now that the code uses self.contentPadding
in SDCAlertViewContentView
, I found an issue.
When the content view is initialized, the appearance hasn't yet been applied, so when initializing the title and message labels, the following doesn't work:
self.titleLabel.preferredMaxLayoutWidth = SDCAlertViewWidth - self.contentPadding.left - self.contentPadding.right;
self.messageLabel.preferredMaxLayoutWidth = SDCAlertViewWidth - self.contentPadding.left - self.contentPadding.right;
This is because self.contentPadding
isn't yet initialized here, so the layout widths don't get set right, and I'm finding that the end result is that sometimes my labels don't get sized properly.
I had used an instance of SDCAlertView in my project to add a UITextView inside an alert to do some facebook posts.It doesnt seem to work properly anymore on ios8.
I had used the following code.
SDCAlertView *alert = [[SDCAlertView alloc] initWithTitle:@"Post To Facebook"
message:@""
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Post", nil];
UITextView *textView = [[UITextView alloc] init];
[textView setTranslatesAutoresizingMaskIntoConstraints:NO];
[textView setEditable:YES];
textView.autocorrectionType = UITextAutocorrectionTypeNo;
[alert.contentView addSubview:textView];
[textView sdc_pinWidthToWidthOfView:alert.contentView offset:-5];
[textView sdc_pinHeight:120];
[textView sdc_horizontallyCenterInSuperview];
[textView sdc_verticallyCenterInSuperviewWithOffset:SDCAutoLayoutStandardSiblingDistance];
[alert showWithDismissHandler: ^(NSInteger buttonIndex) {
NSLog(@"Tapped button: %@", @(buttonIndex));
if (buttonIndex == 1) {
NSLog(@"POST %@", textView.text);
}
else {
NSLog(@"Cancelled");
}
}];
Setting the cancelButtonIndex
property doesn't do much right now, except for causing the model and view to be out of sync. UIAlertView
allows setting an "other" button to be the cancel button, so SDCAlertView should do the same.
I have several UIImages that render according to tintAdjustmentMode and when the alerts show they gray out nicely, as expected, but on dismissal the whole alert fades and then the tintAdjustmentMode suddenly snaps off
I found that but setting the mode to Automatic before the last alert dismisses fixes this issue, or at least the ugly snap I was seeing before is less noticeable since it happens as the alert fades away
Cheers
sdcalertvew with textfield , position not correct when landscape , and can't not dismiss
Hi there, I'm trying to make a safari extension for iOS 8 at the moment, and I found that SDCAlertView doesn't get shown at all when I call [alert show], and it seems that the built-in UIAlertView doesn't get shown either. The only way to get an alert is to use the new UIAlertController, and it still doesn't support subviews...
Will SDCAlertView be updated to support usage in extension context?
In the latest version of SDCAlertView you can't set the type of keyboard input on a textfield because they are not set up in the alertContentView prior to calling [show]
The podspec file is not set up to include the background image(s) (SDCAlertViewBackground.png and its Retina equivalent) in version 0.9. For now, download the image(s) separately and add them manually.
When I create an SDCAlertView using one of the convenience class methods and then set alertViewStyle to e.g. SDCAlertViewStylePlainTextInput, I get an NSInvalidArgumentException related to layout constraints.
I'm not sure if this is a misunderstanding on my part or a (documentation?) bug.
How can I download the library using pods? what's the procedure? Does this library support iOS8 platform?
Instead of requiring the contentView
's height to be set manually, it should be able to deduct the height based on the subviews. Since most of the time the height is determined by [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(view)]
, giving it an intrinsic content size makes that constraint obsolete.
It could probably use the functionality of SDCIntrinsicallySizedView for this functionality.
This issue continues the discussion in #12, which has been fixed but in a way that's not recommended as it has the potential to break or even be rejected by Apple.
A UIToolbar
, which internally uses _UIBackdropView
(a private class) to create its background, is added as the top-level subview of an SDCAlertView
instance to provide the alert with the same background as UIAlertView
. This is obviously not how UIToolbar
is supposed to be used, which is why it's a hack.
UIAlertView
uses that same _UIBackdropView
class, but SDCAlertView
can't use that due to it's privateness. _UIBackdropView
has a huge number of methods and properties and reverse-engineering this won't be easy.
I suspect there may be some issues with the queuing code that are worth investigating.
In particular, if I try to dismiss one SDCAlertView (using dismissWithClickedButtonIndex()) and show another in the same block of code (using show()), the first one goes away but the second one never appears (or briefly appears). After doing this, subsequent calls to show() also don't work.
I have found a workaround (call the show before the dismiss), but this leads to some awkward code readability and I think is just masking the underlying issue. Let me know if you'd prefer I file things like this elsewhere, and thanks for a fantastic library!
In iOS6, I implemented an alert which contains a UITableView. With iOS7 clearly the default alert doesn't work.
With your implementation I have managed to dynamically switch in SDCAlertView as the superclass if the current version is iOS7 or newer.
For most situations this works, however for tableViews, while they appear correctly on the alert, they don't seem to receive any touches - so if you try to tap on a cell, nothing happens.
I'm still early in debugging this, and it may well be something simple with my implementation. I thought it best though to check with you to see if this is a known issue and/or if there is a work around for it.
in using SDCAlertView I want to display an image in the contentView which is 500x500 dimensions. You have a const SDCAlertViewWidth defined as 270 so max width is 270. Is it possible to give a method to allow me to override this and set the width to whatever I want in order to display the contentView nicely?
Hi, great work with this alert!
I found a problem when we set nil cancel button title, and add two 'other' buttontitles.
When showing the view in this case, the 'other' button titles repeat first title, and 2nd one is never shown.
I'll try to fix it later if I have some time. Tell me if you will fix it so we will not work on same thing. Seems related to #2
We subclass SDCAlertView and our subclass had an init function. That caused an infinite loop.
We called our init
Our init actually called another initWith... function of ours
Our initWith... function called initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles: on SDCAlertView
That called init (which was OUR init not the SDCAlertView init)
... and the infinite loop continues.
Easy fix for us. We just had to remove our init function and do things a different way, but that may surprise other people that attempt to subclass SDCAlertView.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.