Chcę UIView, który może wyskoczyć jak UIAlertView, a także można przenieść.UIView Popup jak UIAlertView
Proszę o pomoc?
Dziękuję.
Chcę UIView, który może wyskoczyć jak UIAlertView, a także można przenieść.UIView Popup jak UIAlertView
Proszę o pomoc?
Dziękuję.
animowanie widok na transformację przy użyciu animacji UIView (using blocks lub older api)
z jakiegoś naprawdę niewielkich rozmiarów (jak view.transform = CGAffineTransformMakeScale(0.1, 0.1)
) do czegoś większego to chcesz go mieć (jak view.transform = CGAffineTransformMakeScale(1.1, 1.1))
, a następnie z powrotem do pożądanej wielkości .. (view.transform = CGAffineTransformMakeScale(0.1, 0.1))
lub dodać kolejne kroki do większego odbicia
i przesuwając go dookoła, wdrożenie touch methods i zmienić ramkę widoku jako ruchy palców
Edycja: tutaj jest przykładowy kod dla niestandardowego interfejsu UIAlertView UIView.
MyAlertView.h:
#import <UIKit/UIKit.h>
@interface MyAlertView : UIView {
CGPoint lastTouchLocation;
CGRect originalFrame;
BOOL isShown;
}
@property (nonatomic) BOOL isShown;
- (void)show;
- (void)hide;
@end
MyAlertView.m:
#import "MyAlertView.h"
@implementation MyAlertView
@synthesize isShown;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
originalFrame = frame;
self.alpha = 0;
self.backgroundColor = [UIColor whiteColor];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 20)];
label.text = @"Hellooooo!";
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
[self addSubview:label];
[label release];
UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
closeButton.frame = CGRectMake(10, frame.size.height - 45, frame.size.width - 20, 35);
[closeButton setTitle:@"Close" forState:UIControlStateNormal];
[closeButton addTarget:self action:@selector(hide) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:closeButton];
}
return self;
}
#pragma mark Custom alert methods
- (void)show
{
NSLog(@"show");
isShown = YES;
self.transform = CGAffineTransformMakeScale(0.1, 0.1);
self.alpha = 0;
[UIView beginAnimations:@"showAlert" context:nil];
[UIView setAnimationDelegate:self];
self.transform = CGAffineTransformMakeScale(1.1, 1.1);
self.alpha = 1;
[UIView commitAnimations];
}
- (void)hide
{
NSLog(@"hide");
isShown = NO;
[UIView beginAnimations:@"hideAlert" context:nil];
[UIView setAnimationDelegate:self];
self.transform = CGAffineTransformMakeScale(0.1, 0.1);
self.alpha = 0;
[UIView commitAnimations];
}
- (void)toggle
{
if (isShown) {
[self hide];
} else {
[self show];
}
}
#pragma mark Animation delegate
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
if ([animationID isEqualToString:@"showAlert"]) {
if (finished) {
[UIView beginAnimations:nil context:nil];
self.transform = CGAffineTransformMakeScale(1.0, 1.0);
[UIView commitAnimations];
}
} else if ([animationID isEqualToString:@"hideAlert"]) {
if (finished) {
self.transform = CGAffineTransformMakeScale(1.0, 1.0);
self.frame = originalFrame;
}
}
}
#pragma mark Touch methods
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
lastTouchLocation = [touch locationInView:self];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint newTouchLocation = [touch locationInView:self];
CGRect currentFrame = self.frame;
CGFloat deltaX = lastTouchLocation.x - newTouchLocation.x;
CGFloat deltaY = lastTouchLocation.y - newTouchLocation.y;
self.frame = CGRectMake(currentFrame.origin.x - deltaX, currentFrame.origin.y - deltaY, currentFrame.size.width, currentFrame.size.height);
lastTouchLocation = [touch locationInView:self];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
}
@end
Więc gdzie chcesz pokazać, że alert, musisz:
#import "MyAlertView.h"
oraz:
MyAlertView *alert = [[MyAlertView alloc] initWithFrame:CGRectMake(20, 100, 280, 100)];
[viewFromWhichYouWillShowTheAlert addSubview:alert];
[alert release];
następnie pokażesz go za pomocą [alert show];
, ukryć za pomocą [alert hide];
lub przełączać za pomocą [alert toggle];
Można także przenieść go wokół po dotknięciu i przeciągnięcie (wszędzie z wyjątkiem przycisku zamykania). Mam nadzieję, że to wystarczy, aby zacząć. Jeśli potrzebujesz wyjaśnienia jakiejkolwiek części kodu, po prostu zapytaj.
Aha, i zauważ, że ustawiam kolor tego widoku na biały, więc jeśli pokazujesz go na innym białym widoku, naprawdę go nie zobaczysz, więc po prostu zmień kolor tła dowolnego widoku :)
można nabyć, że po prostu po kolejnych krokach
Na koniec możesz pokazać ten widok tam, gdzie jest to wymagane. Efekt będzie widoczny, ViewA obejmie Background viewController, ViewB będzie serwerem jako efekt tłumienia dla kontrolera widoku w tle, a widoki B to UCIEL, który zobaczysz.
Dla efektu animacji można użyć podstawowego kodu animacji na UIElement w ViewB.