当前位置: 编程技术>移动开发
本页文章导读:
▪本地通报(二) 本地通知(二)
以前写过一篇文章:本地通知,本文是基于此基础的一个简单的例子。
localnotificationAppDelegate.h
#import <UIKit/UIKit.h>
@class localnotificationViewController;
@interface localnotifi.........
▪ 被TranslateAnimation弄晕了 被TranslateAnimation搞晕了。
bottomFrameAnimationOut = new TranslateAnimation(TranslateAnimation.RELATIVE_TO_SELF, 0f, TranslateAnimation.RELATIVE_TO_SELF, 0f, TranslateAnimation.ABSOLUTE, -205, TranslateAnimation.ABSOLUTE, 0);原来这里的每.........
▪ Dialog调用dismiss方法出现错误解决办法 Dialog调用dismiss方法出现异常解决方法
本文原创,转载请保留原文地址: http://maosidiaoxian.iteye.com/blog/1547445在使用Dialog时,调用dismiss方法,有时会出现异常:java.lang.IllegalArgumentException: View .........
[1]本地通报(二)
来源: 互联网 发布时间: 2014-02-18
本地通知(二)
以前写过一篇文章:本地通知,本文是基于此基础的一个简单的例子。
localnotificationAppDelegate.h
#import <UIKit/UIKit.h> @class localnotificationViewController; @interface localnotificationAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; localnotificationViewController *viewController; } @property(nonatomic, retain) IBOutlet UIWindow *window; @property(nonatomic, retain) IBOutlet localnotificationViewController *viewController; @end
localnotificationAppDelegate.m
#import "localnotificationAppDelegate.h" #import "localnotificationViewController.h" @implementation localnotificationAppDelegate @synthesize window; @synthesize viewController; #pragma mark - #pragma mark Application lifecycle - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { application.applicationIconBadgeNumber = 0; [self.window addSubview:viewController.view]; [self.window makeKeyAndVisible]; return YES; } #pragma mark - #pragma mark Memory management - (void)dealloc { [viewController release]; [window release]; [super dealloc]; } @end
localnotificationViewController.h
#import <UIKit/UIKit.h> @interface localnotificationViewController : UIViewController { IBOutlet UILabel *myLable1; IBOutlet UILabel *myLable2; IBOutlet UILabel *myLable3; } @property(nonatomic, retain) UILabel *myLable1; @property(nonatomic, retain) UILabel *myLable2; @property(nonatomic, retain) UILabel *myLable3; - (IBAction)onChangeValue:(id)sender; @end
localnotificationViewController.m
#import "localnotificationViewController.h" @implementation localnotificationViewController @synthesize myLable1, myLable2, myLable3; - (void)viewDidLoad { [super viewDidLoad]; [[UIApplication sharedApplication] cancelAllLocalNotifications]; } - (void)viewDidUnload { self.myLable1 = nil; self.myLable2 = nil; self.myLable3 = nil; } - (void)dealloc { [myLable1 release], myLable1 = nil; [myLable2 release], myLable2 = nil; [myLable3 release], myLable3 = nil; [super dealloc]; } #pragma mark - #pragma mark onChageValue - (IBAction)onChangeValue:(id)sender { UISwitch *switchBtn = (UISwitch *)sender; if (switchBtn.on) { UILocalNotification *notification = [[UILocalNotification alloc] init]; NSDate *now = [NSDate date]; notification.timeZone = [NSTimeZone defaultTimeZone]; notification.repeatInterval = NSDayCalendarUnit; notification.applicationIconBadgeNumber = 1; notification.alertAction = NSLocalizedString(@"显示", nil); switch (switchBtn.tag) { case 0: { notification.fireDate = [now dateByAddingTimeInterval:5]; notification.alertBody = self.myLable1.text; } break; case 1: { notification.fireDate = [now dateByAddingTimeInterval:10]; notification.alertBody = self.myLable2.text; } break; case 2: { notification.fireDate = [now dateByAddingTimeInterval:15]; notification.alertBody = self.myLable3.text; } break; default: break; } [notification setSoundName:UILocalNotificationDefaultSoundName]; NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat:@"%d", switchBtn.tag], @"key", nil]; [notification setUserInfo:dic]; [[UIApplication sharedApplication] scheduleLocalNotification:notification]; } else { NSArray *array = [[UIApplication sharedApplication] scheduledLocalNotifications]; for (int i = 0; i < [array count]; i++) { UILocalNotification *myUILocalNotification = [array objectAtIndex:i]; if ([[[myUILocalNotification userInfo] objectForKey:@"key"] intValue] == switchBtn.tag) { [[UIApplication sharedApplication] cancelLocalNotification:myUILocalNotification]; } } } } @end
效果图:
[2] 被TranslateAnimation弄晕了
来源: 互联网 发布时间: 2014-02-18
被TranslateAnimation搞晕了。
原来这里的每一个参数都是相对于当前view的值。
如果你想点击一个按钮然后把一个view从一个地方移到另一个地方的话。
其实在你startAnimation的时候View的位置已经变了。 Animation里面的参数值是需要相对你移动view之后的值。 有点晕 fuck
bottomFrameAnimationOut = new TranslateAnimation(TranslateAnimation.RELATIVE_TO_SELF, 0f, TranslateAnimation.RELATIVE_TO_SELF, 0f, TranslateAnimation.ABSOLUTE, -205, TranslateAnimation.ABSOLUTE, 0);
原来这里的每一个参数都是相对于当前view的值。
如果你想点击一个按钮然后把一个view从一个地方移到另一个地方的话。
mailboxHeaderBar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mailboxHeaderBar.getLayoutParams(); int bottomMargin = layoutParams.bottomMargin; if (bottomMargin < 0) { mailboxHeaderBar.startAnimation(bottomFrameAnimationIn); layoutParams.bottomMargin = 0; }else{ mailboxHeaderBar.startAnimation(bottomFrameAnimationOut); layoutParams.bottomMargin = -205; } mailboxHeaderBar.setLayoutParams(layoutParams); } });
其实在你startAnimation的时候View的位置已经变了。 Animation里面的参数值是需要相对你移动view之后的值。 有点晕 fuck
[3] Dialog调用dismiss方法出现错误解决办法
来源: 互联网 发布时间: 2014-02-18
Dialog调用dismiss方法出现异常解决方法
本文原创,转载请保留原文地址: http://maosidiaoxian.iteye.com/blog/1547445
在使用Dialog时,调用dismiss方法,有时会出现异常:java.lang.IllegalArgumentException: View not attached to window manager
出现这个异常的原因可能是,在dismiss对话框的时候,它所在的activity因为一些原因已经先退出了,所以会出现这个异常。
目前我认为最好的解决方法是,使用Activity里面封装好的showDialog(int id)和dismissDialog(int id)方法。
使用示例代码如下(代码取自我的一个项目,去掉与本主题无关内容,如果有小的错误,请自行调试):
本文原创,转载请保留原文地址: http://maosidiaoxian.iteye.com/blog/1547445
在使用Dialog时,调用dismiss方法,有时会出现异常:java.lang.IllegalArgumentException: View not attached to window manager
出现这个异常的原因可能是,在dismiss对话框的时候,它所在的activity因为一些原因已经先退出了,所以会出现这个异常。
目前我认为最好的解决方法是,使用Activity里面封装好的showDialog(int id)和dismissDialog(int id)方法。
使用示例代码如下(代码取自我的一个项目,去掉与本主题无关内容,如果有小的错误,请自行调试):
/* * @(#)SearchActivity.java Project:lol * Date:2012-4-29 * * Copyright (c) 2011 CFuture09, Institute of Software, * Guangdong Ocean University, Zhanjiang, GuangDong, China. * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.sinaapp.msdxblog.android.lol.activity; import android.app.Activity; import android.app.Dialog; import android.app.ProgressDialog; import android.content.Context; import android.view.View; import android.view.View.OnClickListener; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.FrameLayout; import android.widget.FrameLayout.LayoutParams; import android.widget.LinearLayout; import com.sinaapp.msdxblog.android.lol.R; import com.sinaapp.msdxblog.androidkit.thread.HandlerFactory; /** * @author Geek_Soledad (66704238@51uc.com) */ public abstract class WebViewActivity extends Activity { protected WebView mSearchWV; protected Context mContext; private static final int PROGRESS_ID = 1; /** * 返回需要加载的URL地址。 * * @return 需要加载的URL地址。 */ protected abstract String getHomeUrl(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; mSearchWV = new WebView(mContext); mSearchWV.getSettings().setJavaScriptEnabled(true); mSearchWV.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(/blog_article/url/index.html); return true; } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); showDialog(PROGRESS_ID); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); dismissDialog(PROGRESS_ID); } }); addContentView(mSearchWV, new FrameLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); mSearchWV.loadUrl(getHomeUrl()); } @Override protected Dialog onCreateDialog(int id) { if (id == PROGRESS_ID) { return ProgressDialog.show(mContext, null, mContext.getString(R.string.loading)); } return super.onCreateDialog(id); } }
最新技术文章: